From 47ce027eb561afae1dc02b52d7d96920784214cf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mat=C3=ADas=20Onorato?= Date: Wed, 21 Feb 2024 17:50:14 -0300 Subject: [PATCH] add validium mode example --- validium_mode_example/.gitignore | 1 + validium_mode_example/BytesWriter.abi | 39 +++ validium_mode_example/BytesWriter.bin | 1 + validium_mode_example/BytesWriter.sol | 27 ++ validium_mode_example/Cargo.toml | 16 + validium_mode_example/Context.sol | 23 ++ validium_mode_example/ERC20.abi | 416 +++++++++++++++++++++++ validium_mode_example/ERC20.bin | 1 + validium_mode_example/ERC20.sol | 368 ++++++++++++++++++++ validium_mode_example/Greeter.abi | 39 +++ validium_mode_example/Greeter.bin | 1 + validium_mode_example/Greeter.sol | 18 + validium_mode_example/IERC20.sol | 81 +++++ validium_mode_example/IERC20Metadata.sol | 27 ++ validium_mode_example/README.md | 72 ++++ validium_mode_example/src/main.rs | 269 +++++++++++++++ 16 files changed, 1399 insertions(+) create mode 100644 validium_mode_example/.gitignore create mode 100644 validium_mode_example/BytesWriter.abi create mode 100644 validium_mode_example/BytesWriter.bin create mode 100644 validium_mode_example/BytesWriter.sol create mode 100644 validium_mode_example/Cargo.toml create mode 100644 validium_mode_example/Context.sol create mode 100644 validium_mode_example/ERC20.abi create mode 100644 validium_mode_example/ERC20.bin create mode 100644 validium_mode_example/ERC20.sol create mode 100644 validium_mode_example/Greeter.abi create mode 100644 validium_mode_example/Greeter.bin create mode 100644 validium_mode_example/Greeter.sol create mode 100644 validium_mode_example/IERC20.sol create mode 100644 validium_mode_example/IERC20Metadata.sol create mode 100644 validium_mode_example/README.md create mode 100644 validium_mode_example/src/main.rs diff --git a/validium_mode_example/.gitignore b/validium_mode_example/.gitignore new file mode 100644 index 000000000000..ea8c4bf7f35f --- /dev/null +++ b/validium_mode_example/.gitignore @@ -0,0 +1 @@ +/target diff --git a/validium_mode_example/BytesWriter.abi b/validium_mode_example/BytesWriter.abi new file mode 100644 index 000000000000..4ac2b64a62e8 --- /dev/null +++ b/validium_mode_example/BytesWriter.abi @@ -0,0 +1,39 @@ +[ + { + "inputs": [ + { + "internalType": "bytes", + "name": "_message", + "type": "bytes" + } + ], + "stateMutability": "nonpayable", + "type": "constructor" + }, + { + "inputs": [], + "name": "readBytes", + "outputs": [ + { + "internalType": "bytes", + "name": "", + "type": "bytes" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "bytes", + "name": "_message", + "type": "bytes" + } + ], + "name": "writeBytes", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + } +] diff --git a/validium_mode_example/BytesWriter.bin b/validium_mode_example/BytesWriter.bin new file mode 100644 index 000000000000..979b0f1ee733 --- /dev/null +++ b/validium_mode_example/BytesWriter.bin @@ -0,0 +1 @@ +00050000000000020000008003000039000000400030043f0000000003010019000000600330027000000073033001970000000102200190000000960000c13d000000040230008c000001600000413d000000000201043b000000e0022002700000007a0420009c0000014e0000613d0000007b0220009c000001600000c13d0000000002000416000000000202004b000001600000c13d000000040230008a000000200220008c000001600000413d0000000402100370000000000502043b000000770250009c000001600000213d00000023025000390000007f04000041000000000632004b000000000600001900000000060480190000007f02200197000000000702004b00000000040080190000007f0220009c000000000406c019000000000204004b000001600000c13d0000000406500039000000000261034f000000000402043b000000770240009c0000009c0000213d000000bf07400039000000200200008a000000000727016f000000770870009c0000009c0000213d000000400070043f000000800040043f00000000054500190000002405500039000000000335004b000001600000213d0000002003600039000000000131034f0000001f0340018f0000000505400272000000440000613d00000000060000190000000507600210000000000871034f000000000808043b000000a00770003900000000008704350000000106600039000000000756004b0000003c0000413d000000000603004b000000530000613d0000000505500210000000000151034f0000000303300210000000a005500039000000000605043300000000063601cf000000000636022f000000000101043b0000010003300089000000000131022f00000000013101cf000000000161019f0000000000150435000000a0014000390000000000010435000000800100043d000000770310009c0000009c0000213d000000000400041a000000010340019000000001054002700000007f0350018f000000000305c0190000001f0530008c00000000050000190000000105002039000000000454013f00000001044001900000015c0000c13d000000200430008c000000750000413d0000001f0410003900000005044002700000007c054000410000007c04000041000000200610008c000000000405801900000000000004350000001f0330003900000005033002700000007c03300041000000000534004b000000750000813d000000000004041b0000000104400039000000000534004b000000710000413d0000001f0310008c0000019f0000a13d0000000003210170000000a0040000390000007c020000410000000000000435000000890000613d0000007c0200004100000020060000390000000004000019000000000506001900000080065000390000000006060433000000000062041b000000200650003900000001022000390000002004400039000000000734004b0000007f0000413d000000a004500039000000000313004b000000930000813d0000000303100210000000f80330018f000000010500008a000000000335022f000000000353013f0000000004040433000000000334016f000000000032041b00000001020000390000000103100210000001a90000013d0000000002000416000000000202004b000001600000c13d0000007402300041000000750220009c000000a20000213d000000800100004100000000001004350000004101000039000000040010043f0000008101000041000001c9000104300000009f023000390000007602200197000000400020043f0000001f0230018f0000000504300272000000b10000613d00000000050000190000000506500210000000000761034f000000000707043b000000800660003900000000007604350000000105500039000000000645004b000000a90000413d000000000502004b000000c00000613d0000000504400210000000000141034f00000003022002100000008004400039000000000504043300000000052501cf000000000525022f000000000101043b0000010002200089000000000121022f00000000012101cf000000000151019f0000000000140435000000200130008c000001600000413d000000800400043d000000770140009c000001600000213d00000080033000390000009f01400039000000000131004b000001600000813d00000080024000390000000001020433000000770510009c0000009c0000213d0000003f05100039000000200900008a000000000595016f000000400800043d0000000005580019000000000685004b00000000060000190000000106004039000000770750009c0000009c0000213d00000001066001900000009c0000c13d000000400050043f00000000061804360000000004140019000000a004400039000000000334004b000001600000213d000000000301004b000000e90000613d000000000300001900000000046300190000002003300039000000000523001900000000050504330000000000540435000000000413004b000000e20000413d000000000116001900000000000104350000000004080433000000770140009c0000009c0000213d000000000100041a000000010210019000000001011002700000007f0310018f000000000301c0190000001f0130008c00000000010000190000000101002039000000010110018f000000000112004b0000015c0000c13d000000200130008c0000011f0000413d000100000003001d000300000004001d000000000000043500000073010000410000000002000414000000730320009c0000000002018019000000c00120021000000078011001c70000801002000039000500000008001d000400000009001d000200000006001d01c701c20000040f0000000206000029000000040900002900000005080000290000000102200190000001600000613d00000003040000290000001f024000390000000502200270000000200340008c0000000002004019000000000301043b00000001010000290000001f01100039000000050110027000000000011300190000000002230019000000000312004b0000011f0000813d000000000002041b0000000102200039000000000312004b0000011b0000413d0000001f0140008c000001b10000a13d000300000004001d000000000000043500000073010000410000000002000414000000730320009c0000000002018019000000c00120021000000078011001c70000801002000039000500000008001d000400000009001d01c701c20000040f000000040300002900000005060000290000000102200190000001600000613d000000030700002900000000033701700000002002000039000000000101043b000001400000613d0000002002000039000000000400001900000000056200190000000005050433000000000051041b000000200220003900000001011000390000002004400039000000000534004b000001380000413d000000000373004b0000014b0000813d0000000303700210000000f80330018f000000010400008a000000000334022f000000000343013f00000000026200190000000002020433000000000232016f000000000021041b00000001010000390000000102700210000001bb0000013d0000000001000416000000000101004b000001600000c13d000000000100041a000000010310019000000001041002700000007f0240018f000000000204c0190000001f0420008c00000000040000190000000104002039000000000441013f0000000104400190000001620000613d0000008001000041000000000010043500000022010000390000009f0000013d0000000001000019000001c900010430000000800020043f000000000303004b000001750000613d000000a0010000390000000000000435000000000302004b000001810000613d0000007c0100004100000000040000190000000003040019000000000401041a000000a005300039000000000045043500000001011000390000002004300039000000000524004b0000016b0000413d000000c0013000390000017b0000013d000001000300008a000000000131016f000000a00010043f000000000102004b000000c001000039000000a0010060390000001f01100039000000200200008a000000000121016f0000007d021000410000007e0220009c0000009c0000413d000000400010043f00000020020000390000000003210436000000800200043d00000000002304350000004003100039000000000402004b000001910000613d00000000040000190000000005340019000000a006400039000000000606043300000000006504350000002004400039000000000524004b0000018a0000413d000000000332001900000000000304350000005f02200039000000200300008a000000000232016f0000007303000041000000730420009c0000000002038019000000730410009c000000000103801900000040011002100000006002200210000000000112019f000001c80001042e000000000201004b0000000002000019000001a30000613d000000a00200043d0000000303100210000000010400008a000000000334022f000000000343013f000000000332016f0000000102100210000000000123019f000000000010041b0000007301000041000000400200043d000000730320009c00000000020180190000004001200210000001c80001042e000000000104004b0000000001000019000001b50000613d00000000010604330000000302400210000000010300008a000000000223022f000000000232013f000000000221016f0000000101400210000000000112019f000000000010041b0000002001000039000001000010044300000120000004430000007901000041000001c80001042e000001c5002104230000000102000039000000000001042d0000000002000019000000000001042d000001c700000432000001c80001042e000001c9000104300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffff000000000000009fffffffffffffffffffffffffffffffffffffffffffffffff000000000000007f00000000000000000000000000000000000000000000000000000001ffffffe0000000000000000000000000000000000000000000000000ffffffffffffffff0200000000000000000000000000000000000020000000000000000000000000000000020000000000000000000000000000004000000100000000000000000000000000000000000000000000000000000000000000000000000000d98b5568000000000000000000000000000000000000000000000000000000007932db75290decd9548b62a8d60345a988386fc84ba6bc95484008f6362f93160ef3e563ffffffffffffffffffffffffffffffffffffffffffffffff0000000000000000ffffffffffffffffffffffffffffffffffffffffffffffff000000000000008080000000000000000000000000000000000000000000000000000000000000004e487b71000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000024000000000000000000000000b6a433bc7df435258118f8b80ff5a7799eb18cd0bf3a38b685cb901f1d11d13f \ No newline at end of file diff --git a/validium_mode_example/BytesWriter.sol b/validium_mode_example/BytesWriter.sol new file mode 100644 index 000000000000..0327d2933728 --- /dev/null +++ b/validium_mode_example/BytesWriter.sol @@ -0,0 +1,27 @@ +//SPDX-License-Identifier: Unlicense +pragma solidity ^0.8.8; + +contract BytesWriter { + bytes private message; + + constructor(bytes memory _message) { + message = _message; + } + + function readBytes() public view returns (bytes memory) { + return message; + } + + function writeBytes(bytes memory _message) public { + message = _message; + } + + // event StringBytesLengthMessage(address sender, string inputString, uint256 bytesLength); + + // function getStringBytesLength(string memory str) external { + // bytes memory strBytes = bytes(str); + // uint256 length = strBytes.length; + + // emit StringBytesLengthMessage(msg.sender, str, length); + // } +} diff --git a/validium_mode_example/Cargo.toml b/validium_mode_example/Cargo.toml new file mode 100644 index 000000000000..2ac5791c83e9 --- /dev/null +++ b/validium_mode_example/Cargo.toml @@ -0,0 +1,16 @@ +[package] +name = "validium_mode_example" +version = "0.1.0" +edition = "2021" +license = "MIT OR Apache-2.0" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +zksync-web3-rs = "*" +zksync_web3_decl = { path = "../core/lib/web3_decl" } +loadnext = { path = "../core/tests/loadnext" } +ethers = "2.0.1" +hex = "0.4.3" +tokio = { version = "1", features = ["macros", "process"] } +colored = "2.0" diff --git a/validium_mode_example/Context.sol b/validium_mode_example/Context.sol new file mode 100644 index 000000000000..df4427b9ebda --- /dev/null +++ b/validium_mode_example/Context.sol @@ -0,0 +1,23 @@ +// SPDX-License-Identifier: MIT + +pragma solidity >=0.8.0; + +/** + * @dev Provides information about the current execution context, including the + * sender of the transaction and its data. While these are generally available + * via msg.sender and msg.data, they should not be accessed in such a direct + * manner, since when dealing with meta-transactions the account sending and + * paying for execution may not be the actual sender (as far as an application + * is concerned). + * + * This contract is only required for intermediate, library-like contracts. + */ +abstract contract Context { + function _msgSender() internal view virtual returns (address) { + return msg.sender; + } + + function _msgData() internal view virtual returns (bytes calldata) { + return msg.data; + } +} diff --git a/validium_mode_example/ERC20.abi b/validium_mode_example/ERC20.abi new file mode 100644 index 000000000000..b6148fda6515 --- /dev/null +++ b/validium_mode_example/ERC20.abi @@ -0,0 +1,416 @@ +[ + { + "inputs": [ + { + "internalType": "string", + "name": "name_", + "type": "string" + }, + { + "internalType": "string", + "name": "symbol_", + "type": "string" + } + ], + "stateMutability": "nonpayable", + "type": "constructor" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "owner", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "spender", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "value", + "type": "uint256" + } + ], + "name": "Approval", + "type": "event" + }, + { + "anonymous": false, + "inputs": [ + { + "indexed": true, + "internalType": "address", + "name": "from", + "type": "address" + }, + { + "indexed": true, + "internalType": "address", + "name": "to", + "type": "address" + }, + { + "indexed": false, + "internalType": "uint256", + "name": "value", + "type": "uint256" + } + ], + "name": "Transfer", + "type": "event" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "from", + "type": "address" + }, + { + "internalType": "address", + "name": "to", + "type": "address" + }, + { + "internalType": "uint256", + "name": "amount", + "type": "uint256" + } + ], + "name": "_afterTokenTransfer", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "owner", + "type": "address" + }, + { + "internalType": "address", + "name": "spender", + "type": "address" + }, + { + "internalType": "uint256", + "name": "amount", + "type": "uint256" + } + ], + "name": "_approve", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "from", + "type": "address" + }, + { + "internalType": "address", + "name": "to", + "type": "address" + }, + { + "internalType": "uint256", + "name": "amount", + "type": "uint256" + } + ], + "name": "_beforeTokenTransfer", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "account", + "type": "address" + }, + { + "internalType": "uint256", + "name": "amount", + "type": "uint256" + } + ], + "name": "_burn", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "account", + "type": "address" + }, + { + "internalType": "uint256", + "name": "amount", + "type": "uint256" + } + ], + "name": "_mint", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "sender", + "type": "address" + }, + { + "internalType": "address", + "name": "recipient", + "type": "address" + }, + { + "internalType": "uint256", + "name": "amount", + "type": "uint256" + } + ], + "name": "_transfer", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "owner", + "type": "address" + }, + { + "internalType": "address", + "name": "spender", + "type": "address" + } + ], + "name": "allowance", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "spender", + "type": "address" + }, + { + "internalType": "uint256", + "name": "amount", + "type": "uint256" + } + ], + "name": "approve", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "account", + "type": "address" + } + ], + "name": "balanceOf", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "decimals", + "outputs": [ + { + "internalType": "uint8", + "name": "", + "type": "uint8" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "spender", + "type": "address" + }, + { + "internalType": "uint256", + "name": "subtractedValue", + "type": "uint256" + } + ], + "name": "decreaseAllowance", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "spender", + "type": "address" + }, + { + "internalType": "uint256", + "name": "addedValue", + "type": "uint256" + } + ], + "name": "increaseAllowance", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [], + "name": "name", + "outputs": [ + { + "internalType": "string", + "name": "", + "type": "string" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "symbol", + "outputs": [ + { + "internalType": "string", + "name": "", + "type": "string" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [], + "name": "totalSupply", + "outputs": [ + { + "internalType": "uint256", + "name": "", + "type": "uint256" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "recipient", + "type": "address" + }, + { + "internalType": "uint256", + "name": "amount", + "type": "uint256" + } + ], + "name": "transfer", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "nonpayable", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "address", + "name": "sender", + "type": "address" + }, + { + "internalType": "address", + "name": "recipient", + "type": "address" + }, + { + "internalType": "uint256", + "name": "amount", + "type": "uint256" + } + ], + "name": "transferFrom", + "outputs": [ + { + "internalType": "bool", + "name": "", + "type": "bool" + } + ], + "stateMutability": "nonpayable", + "type": "function" + } +] diff --git a/validium_mode_example/ERC20.bin b/validium_mode_example/ERC20.bin new file mode 100644 index 000000000000..97fc9e067063 --- /dev/null +++ b/validium_mode_example/ERC20.bin @@ -0,0 +1 @@ +00010000000000020008000000000002000000000701034f00000000000703550000008001000039000000400010043f0000000001070019000000600110027000000152011001970000000102200190000000370000c13d000000040210008c0000038b0000413d000000000207043b000000e0022002700000015a0320009c000001230000a13d0000015b0320009c0000013a0000a13d0000015c0320009c000001660000a13d0000015d0320009c000001f00000613d0000015e0320009c000001b10000613d0000015f0220009c0000038b0000c13d0000000002000416000000000202004b0000038b0000c13d000000040110008a000000400110008c0000038b0000413d0000000401700370000000000101043b000001720210009c0000038b0000213d0000002402700370000000000302043b000001720230009c0000038b0000213d00000000001004350000000101000039000000200010043f0000004002000039000800000002001d0000000001000019000700000003001d054405240000040f00000007020000290000000000200435000000200010043f00000000010000190000000802000029000002a40000013d0000000002000416000000000202004b0000038b0000c13d0000015302100041000001540220009c000000430000213d000001850100004100000000001004350000004101000039000000040010043f000001860100004100000546000104300000009f021000390000015502200197000000400020043f0000001f0210018f0000000503100272000000520000613d00000000040000190000000505400210000000000657034f000000000606043b000000800550003900000000006504350000000104400039000000000534004b0000004a0000413d000000000402004b000000610000613d0000000503300210000000000437034f00000003022002100000008003300039000000000503043300000000052501cf000000000525022f000000000404043b0000010002200089000000000424022f00000000022401cf000000000252019f0000000000230435000000400210008c0000038b0000413d000000800500043d000001560250009c0000038b0000213d00000080021000390000009f03500039000000000323004b0000038b0000813d00000080045000390000000003040433000001560630009c0000003d0000213d0000003f06300039000000200900008a000000000696016f000000400a00043d00000000066a00190000000007a6004b00000000070000190000000107004039000001560860009c0000003d0000213d00000001077001900000003d0000c13d000000400060043f000000000b3a04360000000005350019000000a005500039000000000525004b0000038b0000213d000000000503004b0000008a0000613d000000000500001900000020055000390000000006a50019000000000745001900000000070704330000000000760435000000000635004b000000830000413d00000000033b00190000000000030435000000a00400043d000001560340009c0000038b0000213d0000001f034000390000015705000041000000000113004b000000000100001900000000010580190000015703300197000000000603004b0000000005008019000001570330009c000000000501c019000000000105004b0000038b0000c13d00000080034000390000000001030433000001560510009c0000003d0000213d0000003f05100039000000000595016f000000400800043d0000000005580019000000000685004b00000000060000190000000106004039000001560750009c0000003d0000213d00000001066001900000003d0000c13d000000400050043f0000000005180436000800000005001d0000000004140019000000a004400039000000000224004b0000038b0000213d00040000000b001d00070000000a001d000500000009001d000000000201004b000000be0000613d000000000200001900000020022000390000000004820019000000000532001900000000050504330000000000540435000000000412004b000000b70000413d0000000801100029000000000001043500000007010000290000000001010433000600000001001d000001560110009c0000003d0000213d000100000008001d0000000301000039000300000001001d000000000101041a000000010210019000000001011002700000007f0310018f000000000301c019000200000003001d0000001f0130008c00000000010000190000000101002039000000010110018f000000000112004b000002870000c13d0000000201000029000000200110008c000000f40000413d0000000301000029000000000010043500000152010000410000000002000414000001520320009c0000000002018019000000c00120021000000158011001c700008010020000390544053f0000040f00000001022001900000038b0000613d00000006030000290000001f023000390000000502200270000000200330008c0000000002004019000000000301043b00000002010000290000001f01100039000000050110027000000000011300190000000002230019000000000312004b000000f40000813d000000000002041b0000000102200039000000000312004b000000f00000413d00000006010000290000001f0110008c000003910000a13d0000000301000029000000000010043500000152010000410000000002000414000001520320009c0000000002018019000000c00120021000000158011001c700008010020000390544053f0000040f0000000102200190000000050200002900000007060000290000038b0000613d00000006032001800000002002000039000000000101043b000001130000613d0000002002000039000000000400001900000000056200190000000005050433000000000051041b000000200220003900000001011000390000002004400039000000000534004b0000010b0000413d000000060330006c0000011f0000813d00000006030000290000000303300210000000f80330018f000000010400008a000000000334022f000000000343013f00000007022000290000000002020433000000000232016f000000000021041b0000000601000029000000010110021000000001011001bf0000039e0000013d000001670320009c0000015a0000213d0000016d0320009c000001a40000213d000001700320009c000002070000613d000001710220009c0000038b0000c13d0000000002000416000000000202004b0000038b0000c13d000000040110008a000000400110008c0000038b0000413d0000000401700370000000000201043b000001720120009c0000038b0000213d0000002401700370000000000301043b0000000001000411054404ca0000040f000001fe0000013d000001620320009c000001ad0000213d000001650320009c000002200000613d000001660220009c0000038b0000c13d0000000002000416000000000202004b0000038b0000c13d000000040110008a000000400110008c0000038b0000413d0000000401700370000000000401043b000001720140009c0000038b0000213d0000002401700370000000000201043b000000000104004b000002ba0000c13d0000017801000041000000800010043f0000002001000039000000840010043f0000002101000039000000a40010043f0000018001000041000000c40010043f0000018101000041000000e40010043f00000182010000410000054600010430000001680320009c000001b60000213d0000016b0320009c000002380000613d0000016c0220009c0000038b0000c13d0000000002000416000000000202004b0000038b0000c13d0544042c0000040f054404460000040f000002900000013d000001600320009c000002780000613d000001610220009c0000038b0000c13d0000000002000416000000000202004b0000038b0000c13d000000040110008a000000400110008c0000038b0000413d0000000401700370000000000101043b000800000001001d000001720110009c0000038b0000213d0000002401700370000000000101043b000700000001001d0000000001000411000500000001001d00000000001004350000000101000039000600000001001d000000200010043f00000152030000410000000001000414000001520210009c0000000001038019000000c00110021000000175011001c700008010020000390544053f0000040f00000001022001900000038b0000613d000000000101043b00000008020000290000000000200435000000200010043f0000000001000414000001520210009c0000015201008041000000c00110021000000175011001c700008010020000390544053f0000040f00000001022001900000038b0000613d000000000101043b000000000101041a0000000703000029000000000231004b000003530000813d000000400100043d00000064021000390000017603000041000000000032043500000044021000390000017703000041000000000032043500000024021000390000002503000039000002d60000013d0000016e0320009c0000028b0000613d0000016f0120009c0000038b0000c13d0000000001000416000000000101004b0000038b0000c13d0000000201000039000002a50000013d000001630320009c000002960000613d000001640220009c0000038b0000c13d0000000002000416000000000202004b0000038b0000c13d0544042c0000040f000002900000013d000001690320009c000002a70000613d0000016a0220009c0000038b0000c13d0000000002000416000000000202004b0000038b0000c13d000000040110008a000000400110008c0000038b0000413d0000000401700370000000000101043b000800000001001d000001720110009c0000038b0000213d0000000001000411000500000001001d00000000001004350000000101000039000600000001001d000000200010043f00000152030000410000000001000414000001520210009c0000000001038019000000c00110021000000175011001c7000080100200003900070000000703530544053f0000040f000000070300035f00000001022001900000038b0000613d000000000101043b00000008020000290000000000200435000000200010043f0000002401300370000000000101043b000700000001001d0000000001000414000001520210009c0000015201008041000000c00110021000000175011001c700008010020000390544053f0000040f00000001022001900000038b0000613d000000000101043b000000000101041a0000000703100029000000000113004b000000000100001900000001010040390000000101100190000003540000613d000003000000013d0000000002000416000000000202004b0000038b0000c13d000000040110008a000000400110008c0000038b0000413d0000000401700370000000000201043b000001720120009c0000038b0000213d0000002401700370000000000301043b0000000001000411054404460000040f0000000101000039000000400200043d00000000001204350000015201000041000001520320009c0000000002018019000000400120021000000174011001c7000005450001042e0000000001000416000000000101004b0000038b0000c13d0000000303000039000000000203041a000000010420019000000001052002700000007f0650018f000000000605c0190000001f0560008c00000000050000190000000105002039000000000552013f0000000105500190000002870000c13d000000800060043f000000000404004b000002e20000c13d000001000300008a000000000232016f000000a00020043f000000000106004b000000c001000039000000a001006039000002f10000013d0000000002000416000000000202004b0000038b0000c13d000000040110008a000000400110008c0000038b0000413d0000000401700370000000000401043b000001720140009c0000038b0000213d0000002401700370000000000501043b000000000104004b000002f80000c13d0000017801000041000000800010043f0000002001000039000000840010043f0000001f01000039000000a40010043f0000018301000041000000c40010043f000001840100004100000546000104300000000002000416000000000202004b0000038b0000c13d000000040110008a000000600110008c0000038b0000413d0000000401700370000000000101043b000001720210009c0000038b0000213d0000002402700370000000000202043b000001720320009c0000038b0000213d0000004403700370000000000303043b000700000003001d000800000001001d054404460000040f000000080100002900000000001004350000000101000039000600000001001d000000200010043f00000152030000410000000001000414000001520210009c0000000001038019000000c00110021000000175011001c700008010020000390544053f0000040f00000001022001900000038b0000613d000000000101043b0000000002000411000500000002001d0000000000200435000000200010043f0000000001000414000001520210009c0000015201008041000000c00110021000000175011001c700008010020000390544053f0000040f000000080400002900000001022001900000038b0000613d000000000101043b000000000101041a0000000703000029000000000231004b0000038d0000813d000000400100043d00000064021000390000018703000041000000000032043500000044021000390000018803000041000000000032043500000024021000390000002803000039000002d60000013d0000000001000416000000000101004b0000038b0000c13d0000000403000039000000000203041a000000010420019000000001052002700000007f0650018f000000000605c0190000001f0560008c00000000050000190000000105002039000000000552013f0000000105500190000002b00000613d000001850100004100000000001004350000002201000039000000400000013d0000000002000416000000000202004b0000038b0000c13d0544042c0000040f054404ca0000040f0000015201000041000000400200043d000001520320009c00000000020180190000004001200210000005450001042e0000000002000416000000000202004b0000038b0000c13d000000040110008a000000200110008c0000038b0000413d0000000401700370000000000101043b000001720210009c0000038b0000213d0000000000100435000000200000043f00000040020000390000000001000019054405240000040f000000000101041a000002ad0000013d0000000001000416000000000101004b0000038b0000c13d0000000501000039000000000101041a000000ff0110018f000000800010043f0000017301000041000005450001042e000000800060043f000000000404004b000003040000c13d000001000300008a000000000232016f000000a00020043f000000000106004b000000c001000039000000a001006039000003130000013d000700000002001d0000000000400435000000200000043f00000152010000410000000002000414000001520320009c0000000002018019000000c00120021000000175011001c70000801002000039000800000004001d0544053f0000040f000000080300002900000001022001900000038b0000613d000000000101043b000000000201041a000000070120006c000003600000813d000000400100043d00000064021000390000017e03000041000000000032043500000044021000390000017f030000410000000000320435000000240210003900000022030000390000000000320435000001780200004100000000002104350000000402100039000000200300003900000000003204350000015202000041000001520310009c0000000001028019000000400110021000000179011001c700000546000104300000000000300435000000a001000039000000000206004b000003190000613d000001890200004100000000040000190000000003040019000000000402041a000000a005300039000000000045043500000001022000390000002004300039000000000564004b000002e80000413d000000c0013000390000001f01100039000000200200008a000000000121016f0000017b021000410000017c0220009c0000003d0000413d000003190000013d0000000201000039000000000301041a0000000002530019000000000332004b000000000300001900000001030040390000000103300190000003280000613d000001850100004100000000001004350000001101000039000000400000013d0000000000300435000000a001000039000000000206004b000003190000613d0000017a0200004100000000040000190000000003040019000000000402041a000000a005300039000000000045043500000001022000390000002004300039000000000564004b0000030a0000413d000000c0013000390000001f01100039000000200200008a000000000121016f0000017b021000410000017c0220009c0000003d0000413d000800000001001d000000400010043f0000008002000039054404160000040f000000080400002900000000014100490000015202000041000001520310009c0000000001028019000001520340009c000000000402801900000040024002100000006001100210000000000121019f000005450001042e000700000005001d000000000021041b0000000000400435000000200000043f00000152010000410000000002000414000001520320009c0000000002018019000000c00120021000000175011001c70000801002000039000800000004001d0544053f0000040f000000080600002900000001022001900000038b0000613d000000000101043b000000000301041a00000007040000290000000002430019000000000332004b000000000300001900000001030040390000000103300190000003000000c13d000000000021041b000000400100043d000000000041043500000152020000410000000003000414000001520430009c0000000003028019000001520410009c00000000010280190000004001100210000000c002300210000000000112019f00000158011001c70000800d0200003900000003030000390000017d040000410000000005000019000003880000013d000000000331004900000005010000290000000802000029054404ca0000040f000000400100043d000000060200002900000000002104350000015202000041000001520310009c0000000001028019000000400110021000000174011001c7000005450001042e000600000002001d0000000000300435000000200000043f00000152010000410000000002000414000001520320009c0000000002018019000000c00120021000000175011001c700008010020000390544053f0000040f000000080500002900000001022001900000038b0000613d00000007040000290000000602400069000000000101043b000000000021041b0000000201000039000000000201041a000000000342004b000003000000413d0000000002420049000000000021041b000000400100043d000000000041043500000152020000410000000003000414000001520430009c0000000003028019000001520410009c00000000010280190000004001100210000000c002300210000000000112019f00000158011001c70000800d0200003900000003030000390000017d0400004100000000060000190544053a0000040f0000000101200190000002900000c13d00000000010000190000054600010430000000000331004900000000010400190000000502000029000003560000013d000000060100006b0000000001000019000003960000613d0000000401000029000000000101043300000006040000290000000302400210000000010300008a000000000223022f000000000232013f000000000121016f0000000102400210000000000121019f0000000302000029000000000012041b00000001010000290000000001010433000700000001001d000001560110009c0000003d0000213d0000000401000039000600000001001d000000000101041a000000010210019000000001021002700000007f0320018f000000000302c019000400000003001d0000001f0230008c00000000020000190000000102002039000000000121013f0000000101100190000002870000c13d0000000401000029000000200110008c000003d30000413d0000000601000029000000000010043500000152010000410000000002000414000001520320009c0000000002018019000000c00120021000000158011001c700008010020000390544053f0000040f00000001022001900000038b0000613d00000007030000290000001f023000390000000502200270000000200330008c0000000002004019000000000301043b00000004010000290000001f01100039000000050110027000000000011300190000000002230019000000000312004b000003d30000813d000000000002041b0000000102200039000000000312004b000003cf0000413d00000007010000290000001f0110008c000004020000a13d0000000601000029000000000010043500000152010000410000000002000414000001520320009c0000000002018019000000c00120021000000158011001c700008010020000390544053f0000040f0000000102200190000000050200002900000001060000290000038b0000613d00000007032001800000002002000039000000000101043b000003f20000613d0000002002000039000000000400001900000000056200190000000005050433000000000051041b000000200220003900000001011000390000002004400039000000000534004b000003ea0000413d000000070330006c000003fe0000813d00000007030000290000000303300210000000f80330018f000000010400008a000000000334022f000000000343013f00000001022000290000000002020433000000000232016f000000000021041b0000000101000039000000070200002900000001022002100000040e0000013d000000070100006b0000000001000019000004070000613d0000000801000029000000000101043300000007040000290000000302400210000000010300008a000000000223022f000000000232013f000000000221016f0000000101400210000000000112019f0000000602000029000000000012041b0000002001000039000001000010044300000120000004430000015901000041000005450001042e00000020030000390000000004310436000000000302043300000000003404350000004001100039000000000403004b000004250000613d000000000400001900000000054100190000002004400039000000000624001900000000060604330000000000650435000000000534004b0000041e0000413d000000000231001900000000000204350000001f02300039000000200300008a000000000232016f0000000001210019000000000001042d000000040110008a00000157020000410000005f0310008c000000000300001900000000030220190000015701100197000000000401004b0000000002008019000001570110009c000000000203c019000000000102004b000004440000613d00000000030003670000000401300370000000000101043b000001720210009c000004440000213d0000002402300370000000000202043b000001720420009c000004440000213d0000004403300370000000000303043b000000000001042d00000000010000190000054600010430000400000000000200000172011001980000049b0000613d000400000003001d000201720020019c000004a50000613d000300000001001d0000000000100435000000200000043f00000152010000410000000002000414000001520320009c0000000002018019000000c00120021000000175011001c700008010020000390544053f0000040f0000000102200190000004990000613d000000000101043b000000000201041a000100000002001d000000040120006c000004af0000413d00000003010000290000000000100435000000200000043f00000152030000410000000001000414000001520210009c0000000001038019000000c00110021000000175011001c700008010020000390544053f0000040f0000000102200190000004990000613d0000000103000029000000040230006a000000000101043b000000000021041b000000020100002900000000001004350000000001000414000001520210009c0000015201008041000000c00110021000000175011001c700008010020000390544053f0000040f0000000102200190000004990000613d000000000101043b000000000301041a00000004040000290000000002430019000000000332004b000000000300001900000001030040390000000103300190000004c40000c13d000000000021041b000000400100043d000000000041043500000152020000410000000003000414000001520430009c0000000003028019000001520410009c00000000010280190000004001100210000000c002300210000000000112019f00000158011001c70000800d0200003900000003030000390000017d04000041000000030500002900000002060000290544053a0000040f0000000101200190000004990000613d000000000001042d00000000010000190000054600010430000000400100043d00000064021000390000018e03000041000000000032043500000044021000390000018f03000041000000000032043500000024021000390000002503000039000004b80000013d000000400100043d00000064021000390000018c03000041000000000032043500000044021000390000018d03000041000000000032043500000024021000390000002303000039000004b80000013d000000400100043d00000064021000390000018a03000041000000000032043500000044021000390000018b030000410000000000320435000000240210003900000026030000390000000000320435000001780200004100000000002104350000000402100039000000200300003900000000003204350000015202000041000001520310009c0000000001028019000000400110021000000179011001c70000054600010430000001850100004100000000001004350000001101000039000000040010043f0000018601000041000005460001043000030000000000020000017201100198000005050000613d000200000003001d000301720020019c0000050f0000613d000100000001001d00000000001004350000000101000039000000200010043f00000152030000410000000001000414000001520210009c0000000001038019000000c00110021000000175011001c700008010020000390544053f0000040f00000001022001900000000303000029000005030000613d000000000101043b0000000000300435000000200010043f0000000001000414000001520210009c0000015201008041000000c00110021000000175011001c700008010020000390544053f0000040f00000003060000290000000102200190000005030000613d000000000101043b0000000202000029000000000021041b000000400100043d000000000021043500000152020000410000000003000414000001520430009c0000000003028019000001520410009c00000000010280190000004001100210000000c002300210000000000112019f00000158011001c70000800d020000390000000303000039000001900400004100000001050000290544053a0000040f0000000101200190000005030000613d000000000001042d00000000010000190000054600010430000000400100043d00000064021000390000019303000041000000000032043500000044021000390000019403000041000000000032043500000024021000390000002403000039000005180000013d000000400100043d000000640210003900000191030000410000000000320435000000440210003900000192030000410000000000320435000000240210003900000022030000390000000000320435000001780200004100000000002104350000000402100039000000200300003900000000003204350000015202000041000001520310009c0000000001028019000000400110021000000179011001c700000546000104300000015203000041000001520410009c00000000010380190000004001100210000001520420009c00000000020380190000006002200210000000000112019f0000000002000414000001520420009c0000000002038019000000c002200210000000000112019f00000195011001c700008010020000390544053f0000040f0000000102200190000005380000613d000000000101043b000000000001042d000000000100001900000546000104300000053d002104210000000102000039000000000001042d0000000002000019000000000001042d00000542002104230000000102000039000000000001042d0000000002000019000000000001042d0000054400000432000005450001042e0000054600010430000000000000000000000000000000000000000000000000000000000000000000000000ffffffffffffffffffffffffffffffffffffffffffffffffffffffff000000000000009fffffffffffffffffffffffffffffffffffffffffffffffff000000000000007f00000000000000000000000000000000000000000000000000000001ffffffe0000000000000000000000000000000000000000000000000ffffffffffffffff800000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000200000000000000000000000000000000200000000000000000000000000000040000001000000000000000000000000000000000000000000000000000000000000000000000000004e6ec2460000000000000000000000000000000000000000000000000000000095d89b4000000000000000000000000000000000000000000000000000000000a9059cba00000000000000000000000000000000000000000000000000000000a9059cbb00000000000000000000000000000000000000000000000000000000cad3be8300000000000000000000000000000000000000000000000000000000dd62ed3e0000000000000000000000000000000000000000000000000000000095d89b4100000000000000000000000000000000000000000000000000000000a457c2d70000000000000000000000000000000000000000000000000000000070a082300000000000000000000000000000000000000000000000000000000070a08231000000000000000000000000000000000000000000000000000000008f811a1c000000000000000000000000000000000000000000000000000000004e6ec247000000000000000000000000000000000000000000000000000000006161eb180000000000000000000000000000000000000000000000000000000023b872dc00000000000000000000000000000000000000000000000000000000313ce56600000000000000000000000000000000000000000000000000000000313ce56700000000000000000000000000000000000000000000000000000000395093510000000000000000000000000000000000000000000000000000000023b872dd0000000000000000000000000000000000000000000000000000000030e0789e00000000000000000000000000000000000000000000000000000000104e81fe00000000000000000000000000000000000000000000000000000000104e81ff0000000000000000000000000000000000000000000000000000000018160ddd0000000000000000000000000000000000000000000000000000000006fdde0300000000000000000000000000000000000000000000000000000000095ea7b3000000000000000000000000ffffffffffffffffffffffffffffffffffffffff000000000000000000000000000000000000002000000080000000000000000000000000000000000000000000000000000000200000000000000000000000000200000000000000000000000000000000000040000000000000000000000000207a65726f00000000000000000000000000000000000000000000000000000045524332303a2064656372656173656420616c6c6f77616e63652062656c6f7708c379a00000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000840000000000000000000000008a35acfbc15ff81a39ae7d344fd709f28e8600b4aa8c65c6b64bfe7fe36bd19bffffffffffffffffffffffffffffffffffffffffffffffff0000000000000000ffffffffffffffffffffffffffffffffffffffffffffffff0000000000000080ddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef636500000000000000000000000000000000000000000000000000000000000045524332303a206275726e20616d6f756e7420657863656564732062616c616e45524332303a206275726e2066726f6d20746865207a65726f206164647265737300000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000008400000080000000000000000045524332303a206d696e7420746f20746865207a65726f20616464726573730000000000000000000000000000000000000000640000008000000000000000004e487b710000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000240000000000000000000000006c6c6f77616e636500000000000000000000000000000000000000000000000045524332303a207472616e7366657220616d6f756e7420657863656564732061c2575a0e9e593c00f959f8c92f12db2869c3395a3b0502d05e2516446f71f85b616c616e6365000000000000000000000000000000000000000000000000000045524332303a207472616e7366657220616d6f756e7420657863656564732062657373000000000000000000000000000000000000000000000000000000000045524332303a207472616e7366657220746f20746865207a65726f2061646472647265737300000000000000000000000000000000000000000000000000000045524332303a207472616e736665722066726f6d20746865207a65726f2061648c5be1e5ebec7d5bd14f71427d1e84f3dd0314c0f7b2291e5b200ac8c7c3b925737300000000000000000000000000000000000000000000000000000000000045524332303a20617070726f766520746f20746865207a65726f206164647265726573730000000000000000000000000000000000000000000000000000000045524332303a20617070726f76652066726f6d20746865207a65726f206164640200000000000000000000000000000000000000000000000000000000000000f7b6a0ef06930cfb358d73424bfb79061f7dc9a44ad5004b52f294ee14c39e12 \ No newline at end of file diff --git a/validium_mode_example/ERC20.sol b/validium_mode_example/ERC20.sol new file mode 100644 index 000000000000..f3da1db61a4b --- /dev/null +++ b/validium_mode_example/ERC20.sol @@ -0,0 +1,368 @@ +// SPDX-License-Identifier: MIT + +pragma solidity >=0.8.0; + +import "./IERC20.sol"; +import "./IERC20Metadata.sol"; +import "./Context.sol"; + +/** + * @dev Implementation of the {IERC20} interface. + * + * This implementation is agnostic to the way tokens are created. This means + * that a supply mechanism has to be added in a derived contract using {_mint}. + * For a generic mechanism see {ERC20PresetMinterPauser}. + * + * TIP: For a detailed writeup see our guide + * https://forum.zeppelin.solutions/t/how-to-implement-erc20-supply-mechanisms/226[How + * to implement supply mechanisms]. + * + * We have followed general OpenZeppelin Contracts guidelines: functions revert + * instead returning `false` on failure. This behavior is nonetheless + * conventional and does not conflict with the expectations of ERC20 + * applications. + * + * Additionally, an {Approval} event is emitted on calls to {transferFrom}. + * This allows applications to reconstruct the allowance for all accounts just + * by listening to said events. Other implementations of the EIP may not emit + * these events, as it isn't required by the specification. + * + * Finally, the non-standard {decreaseAllowance} and {increaseAllowance} + * functions have been added to mitigate the well-known issues around setting + * allowances. See {IERC20-approve}. + */ +contract ERC20 is Context, IERC20, IERC20Metadata { + mapping(address => uint256) private _balances; + + mapping(address => mapping(address => uint256)) private _allowances; + + uint256 private _totalSupply; + + string private _name; + string private _symbol; + + uint8 private _decimals; + + /** + * @dev Sets the values for {name} and {symbol}. + * + * The default value of {decimals} is 18. To select a different value for + * {decimals} you should overload it. + * + * All two of these values are immutable: they can only be set once during + * construction. + */ + constructor(string memory name_, string memory symbol_) { + _name = name_; + _symbol = symbol_; + } + + /** + * @dev Returns the name of the token. + */ + function name() public view virtual override returns (string memory) { + return _name; + } + + /** + * @dev Returns the symbol of the token, usually a shorter version of the + * name. + */ + function symbol() public view virtual override returns (string memory) { + return _symbol; + } + + /** + * @dev Returns the number of decimals used to get its user representation. + * For example, if `decimals` equals `2`, a balance of `505` tokens should + * be displayed to a user as `5.05` (`505 / 10 ** 2`). + * + * Tokens usually opt for a value of 18, imitating the relationship between + * Ether and Wei. This is the value {ERC20} uses, unless this function is + * overridden; + * + * NOTE: This information is only used for _display_ purposes: it in + * no way affects any of the arithmetic of the contract, including + * {IERC20-balanceOf} and {IERC20-transfer}. + */ + function decimals() public view virtual override returns (uint8) { + return _decimals; + } + + /** + * @dev See {IERC20-totalSupply}. + */ + function totalSupply() public view virtual override returns (uint256) { + return _totalSupply; + } + + /** + * @dev See {IERC20-balanceOf}. + */ + function balanceOf(address account) public view virtual override returns (uint256) { + return _balances[account]; + } + + /** + * @dev See {IERC20-transfer}. + * + * Requirements: + * + * - `recipient` cannot be the zero address. + * - the caller must have a balance of at least `amount`. + */ + function transfer(address recipient, uint256 amount) public virtual override returns (bool) { + _transfer(_msgSender(), recipient, amount); + return true; + } + + /** + * @dev See {IERC20-allowance}. + */ + function allowance(address owner, address spender) public view virtual override returns (uint256) { + return _allowances[owner][spender]; + } + + /** + * @dev See {IERC20-approve}. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function approve(address spender, uint256 amount) public virtual override returns (bool) { + _approve(_msgSender(), spender, amount); + return true; + } + + /** + * @dev See {IERC20-transferFrom}. + * + * Emits an {Approval} event indicating the updated allowance. This is not + * required by the EIP. See the note at the beginning of {ERC20}. + * + * Requirements: + * + * - `sender` and `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + * - the caller must have allowance for ``sender``'s tokens of at least + * `amount`. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) public virtual override returns (bool) { + _transfer(sender, recipient, amount); + + uint256 currentAllowance = _allowances[sender][_msgSender()]; + require(currentAllowance >= amount, "ERC20: transfer amount exceeds allowance"); + unchecked { + _approve(sender, _msgSender(), currentAllowance - amount); + } + + return true; + } + + /** + * @dev Atomically increases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + */ + function increaseAllowance(address spender, uint256 addedValue) public virtual returns (bool) { + _approve(_msgSender(), spender, _allowances[_msgSender()][spender] + addedValue); + return true; + } + + /** + * @dev Atomically decreases the allowance granted to `spender` by the caller. + * + * This is an alternative to {approve} that can be used as a mitigation for + * problems described in {IERC20-approve}. + * + * Emits an {Approval} event indicating the updated allowance. + * + * Requirements: + * + * - `spender` cannot be the zero address. + * - `spender` must have allowance for the caller of at least + * `subtractedValue`. + */ + function decreaseAllowance(address spender, uint256 subtractedValue) public virtual returns (bool) { + uint256 currentAllowance = _allowances[_msgSender()][spender]; + require(currentAllowance >= subtractedValue, "ERC20: decreased allowance below zero"); + unchecked { + _approve(_msgSender(), spender, currentAllowance - subtractedValue); + } + + return true; + } + + /** + * @dev Moves `amount` of tokens from `sender` to `recipient`. + * + * This internal function is equivalent to {transfer}, and can be used to + * e.g. implement automatic token fees, slashing mechanisms, etc. + * + * Emits a {Transfer} event. + * + * Requirements: + * + * - `sender` cannot be the zero address. + * - `recipient` cannot be the zero address. + * - `sender` must have a balance of at least `amount`. + */ + function _transfer( + address sender, + address recipient, + uint256 amount + ) public /*internal*/ virtual { + require(sender != address(0), "ERC20: transfer from the zero address"); + require(recipient != address(0), "ERC20: transfer to the zero address"); + + _beforeTokenTransfer(sender, recipient, amount); + + uint256 senderBalance = _balances[sender]; + require(senderBalance >= amount, "ERC20: transfer amount exceeds balance"); + unchecked { + _balances[sender] = senderBalance - amount; + } + _balances[recipient] += amount; + + emit Transfer(sender, recipient, amount); + + _afterTokenTransfer(sender, recipient, amount); + } + + /** @dev Creates `amount` tokens and assigns them to `account`, increasing + * the total supply. + * + * Emits a {Transfer} event with `from` set to the zero address. + * + * Requirements: + * + * - `account` cannot be the zero address. + */ + function _mint(address account, uint256 amount) public /*internal*/ virtual { + require(account != address(0), "ERC20: mint to the zero address"); + + _beforeTokenTransfer(address(0), account, amount); + + _totalSupply += amount; + _balances[account] += amount; + emit Transfer(address(0), account, amount); + + _afterTokenTransfer(address(0), account, amount); + } + + /** + * @dev Destroys `amount` tokens from `account`, reducing the + * total supply. + * + * Emits a {Transfer} event with `to` set to the zero address. + * + * Requirements: + * + * - `account` cannot be the zero address. + * - `account` must have at least `amount` tokens. + */ + function _burn(address account, uint256 amount) public /*internal*/ virtual { + require(account != address(0), "ERC20: burn from the zero address"); + + _beforeTokenTransfer(account, address(0), amount); + + uint256 accountBalance = _balances[account]; + require(accountBalance >= amount, "ERC20: burn amount exceeds balance"); + unchecked { + _balances[account] = accountBalance - amount; + } + _totalSupply -= amount; + + emit Transfer(account, address(0), amount); + + _afterTokenTransfer(account, address(0), amount); + } + + /** + * @dev Sets `amount` as the allowance of `spender` over the `owner` s tokens. + * + * This internal function is equivalent to `approve`, and can be used to + * e.g. set automatic allowances for certain subsystems, etc. + * + * Emits an {Approval} event. + * + * Requirements: + * + * - `owner` cannot be the zero address. + * - `spender` cannot be the zero address. + */ + function _approve( + address owner, + address spender, + uint256 amount + ) public /*internal*/ virtual { + require(owner != address(0), "ERC20: approve from the zero address"); + require(spender != address(0), "ERC20: approve to the zero address"); + + _allowances[owner][spender] = amount; + emit Approval(owner, spender, amount); + } + + /** + * @dev Hook that is called before any transfer of tokens. This includes + * minting and burning. + * + * Calling conditions: + * + * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens + * will be transferred to `to`. + * - when `from` is zero, `amount` tokens will be minted for `to`. + * - when `to` is zero, `amount` of ``from``'s tokens will be burned. + * - `from` and `to` are never both zero. + * + * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. + */ + function _beforeTokenTransfer( + address from, + address to, + uint256 amount + ) public /*internal*/ virtual {} + + /** + * @dev Hook that is called after any transfer of tokens. This includes + * minting and burning. + * + * Calling conditions: + * + * - when `from` and `to` are both non-zero, `amount` of ``from``'s tokens + * has been transferred to `to`. + * - when `from` is zero, `amount` tokens have been minted for `to`. + * - when `to` is zero, `amount` of ``from``'s tokens have been burned. + * - `from` and `to` are never both zero. + * + * To learn more about hooks, head to xref:ROOT:extending-contracts.adoc#using-hooks[Using Hooks]. + */ + function _afterTokenTransfer( + address from, + address to, + uint256 amount + ) public /*internal*/ virtual {} + + /** + * @dev Sets {decimals} to a value other than the default one of 18. + * + * WARNING: This function should only be called from the constructor. Most + * applications that interact with token contracts will not expect + * {decimals} to ever change, and may work incorrectly if it does. + */ + function _setupDecimals(uint8 decimals_) internal { + _decimals = decimals_; + } +} diff --git a/validium_mode_example/Greeter.abi b/validium_mode_example/Greeter.abi new file mode 100644 index 000000000000..a46e53a2bd06 --- /dev/null +++ b/validium_mode_example/Greeter.abi @@ -0,0 +1,39 @@ +[ + { + "inputs": [ + { + "internalType": "string", + "name": "_greeting", + "type": "string" + } + ], + "stateMutability": "nonpayable", + "type": "constructor" + }, + { + "inputs": [], + "name": "greet", + "outputs": [ + { + "internalType": "string", + "name": "", + "type": "string" + } + ], + "stateMutability": "view", + "type": "function" + }, + { + "inputs": [ + { + "internalType": "string", + "name": "_greeting", + "type": "string" + } + ], + "name": "setGreeting", + "outputs": [], + "stateMutability": "nonpayable", + "type": "function" + } +] \ No newline at end of file diff --git a/validium_mode_example/Greeter.bin b/validium_mode_example/Greeter.bin new file mode 100644 index 000000000000..cc5bd5e64fd9 --- /dev/null +++ b/validium_mode_example/Greeter.bin @@ -0,0 +1 @@ +0002000000000002000500000000000200010000000103550000006001100270000000830010019d0000008001000039000000400010043f0000000101200190000000a80000c13d0000000001000031000000040110008c000001880000413d0000000101000367000000000101043b000000e001100270000000880210009c000001770000613d000000890110009c000001880000c13d0000000001000416000000000110004c000001880000c13d0000000001000031000000040210008a0000008503000041000000200420008c000000000400001900000000040340190000008502200197000000000520004c000000000300a019000000850220009c00000000020400190000000002036019000000000220004c000001880000c13d00000001020003670000000403200370000000000303043b000000840430009c000001880000213d00000023043000390000008505000041000000000614004b0000000006000019000000000605801900000085011001970000008504400197000000000714004b0000000005008019000000000114013f000000850110009c00000000010600190000000001056019000000000110004c000001880000c13d0000000401300039000000000112034f000000000101043b000000840210009c000001dc0000213d000000bf04100039000000200200008a000000000424016f000000840540009c000001dc0000213d000000400040043f000000800010043f000000240430003900000000034100190000000005000031000000000353004b000001880000213d0000001f0310018f00000001044003670000000505100272000000560000613d00000000060000190000000507600210000000000874034f000000000808043b000000a00770003900000000008704350000000106600039000000000756004b0000004e0000413d000000000630004c000000650000613d0000000505500210000000000454034f0000000303300210000000a005500039000000000605043300000000063601cf000000000636022f000000000404043b0000010003300089000000000434022f00000000033401cf000000000363019f0000000000350435000000a0011000390000000000010435000000800100043d000000840310009c000001dc0000213d000000000400041a000000010340019000000001034002700000007f0530018f00000000030560190000001f0530008c00000000050000190000000105002039000000000454013f0000000104400190000001960000c13d000000200430008c000000870000413d0000001f0410003900000005044002700000008a044000410000008a05000041000000200610008c000000000405401900000000000004350000001f0330003900000005033002700000008a03300041000000000534004b000000870000813d000000000004041b0000000104400039000000000534004b000000830000413d0000001f0310008c000001f30000a13d00000000032101700000008a02000041000000a00400003900000000000004350000009b0000613d00000020060000390000008a020000410000000004000019000000000506001900000080065000390000000006060433000000000062041b000000200650003900000001022000390000002004400039000000000734004b000000910000413d000000a004500039000000000313004b000000a50000813d0000000303100210000000f80330018f000000010500008a000000000335022f000000000353013f0000000004040433000000000334016f000000000032041b00000001020000390000000103100210000001fd0000013d0000000001000416000000000110004c000001880000c13d00000000010000310000001f02100039000000200900008a000000000492016f000000400200043d0000000003240019000000000443004b00000000040000190000000104004039000000840530009c000001dc0000213d0000000104400190000001dc0000c13d000000400030043f0000001f0310018f00000001040003670000000505100272000000c60000613d000000000600001900000005076002100000000008720019000000000774034f000000000707043b00000000007804350000000106600039000000000756004b000000be0000413d000000000630004c000000d50000613d0000000505500210000000000454034f00000000055200190000000303300210000000000605043300000000063601cf000000000636022f000000000404043b0000010003300089000000000434022f00000000033401cf000000000363019f00000000003504350000008503000041000000200410008c000000000400001900000000040340190000008505100197000000000650004c000000000300a019000000850550009c000000000304c019000000000330004c000001880000c13d0000000004020433000000840340009c000001880000213d000000000312001900000000012400190000001f021000390000008504000041000000000532004b0000000005000019000000000504801900000085022001970000008506300197000000000762004b0000000004008019000000000262013f000000850220009c00000000020500190000000002046019000000000220004c000001880000c13d0000000002010433000000840420009c000001dc0000213d0000003f04200039000000000494016f000000400700043d0000000004470019000000000574004b00000000050000190000000105004039000000840640009c000001dc0000213d0000000105500190000001dc0000c13d000000400040043f000000000627043600000000042100190000002004400039000000000334004b000001880000213d000000000320004c000001120000613d000000000300001900000000046300190000002003300039000000000513001900000000050504330000000000540435000000000423004b0000010b0000413d000000000126001900000000000104350000000004070433000000840140009c000001dc0000213d000000000100041a000000010210019000000001011002700000007f0310018f000000000301c0190000001f0130008c00000000010000190000000101002039000000010110018f000000000112004b000001960000c13d000000200130008c000001480000413d000100000003001d000300000004001d000000000000043500000083010000410000000002000414000000830320009c0000000001024019000000c00110021000000086011001c70000801002000039000500000009001d000400000007001d000200000006001d020602010000040f0000000206000029000000040700002900000005090000290000000102200190000001880000613d00000003040000290000001f024000390000000502200270000000200340008c0000000002004019000000000301043b00000001010000290000001f01100039000000050110027000000000011300190000000002230019000000000312004b000001480000813d000000000002041b0000000102200039000000000312004b000001440000413d0000001f0140008c000001e20000a13d000300000004001d000000000000043500000083010000410000000002000414000000830320009c0000000001024019000000c00110021000000086011001c70000801002000039000500000009001d000400000007001d020602010000040f000000040600002900000005030000290000000102200190000001880000613d000000030700002900000000033701700000002002000039000000000101043b000001690000613d0000002002000039000000000400001900000000056200190000000005050433000000000051041b000000200220003900000001011000390000002004400039000000000534004b000001610000413d000000000373004b000001740000813d0000000303700210000000f80330018f000000010400008a000000000334022f000000000343013f00000000026200190000000002020433000000000232016f000000000021041b00000001010000390000000102700210000001ec0000013d0000000001000416000000000110004c000001880000c13d000000040100008a00000000011000310000008502000041000000000310004c000000000300001900000000030240190000008501100197000000000410004c000000000200a019000000850110009c00000000010300190000000001026019000000000110004c0000018a0000613d00000000010000190000020800010430000000000400041a000000010540019000000001014002700000007f0210018f000000000301001900000000030260190000001f0130008c00000000010000190000000101002039000000000114013f00000001011001900000019c0000613d0000008b0100004100000000001004350000002201000039000000040010043f0000008c010000410000020800010430000000400200043d0000000001320436000000000550004c000001ae0000613d0000000000000435000000000430004c0000000004000019000001b40000613d0000008a0500004100000000040000190000000006410019000000000705041a000000000076043500000001055000390000002004400039000000000634004b000001a60000413d000001b40000013d000001000500008a000000000454016f0000000000410435000000000330004c000000200400003900000000040060190000003f03400039000000200400008a000000000543016f0000000003250019000000000553004b00000000050000190000000105004039000000840630009c000001dc0000213d0000000105500190000001dc0000c13d000000400030043f00000020050000390000000005530436000000000202043300000000002504350000004005300039000000000620004c000001cf0000613d000000000600001900000000075600190000000008610019000000000808043300000000008704350000002006600039000000000726004b000001c80000413d000000000152001900000000000104350000005f01200039000000000141016f0000008302000041000000830410009c0000000001028019000000830430009c000000000203401900000040022002100000006001100210000000000121019f000002070001042e0000008b0100004100000000001004350000004101000039000000040010043f0000008c010000410000020800010430000000000140004c0000000001000019000001e60000613d00000000010604330000000302400210000000010300008a000000000223022f000000000232013f000000000221016f0000000101400210000000000112019f000000000010041b0000002001000039000001000010044300000120000004430000008701000041000002070001042e000000000210004c0000000002000019000001f70000613d000000a00200043d0000000303100210000000010400008a000000000334022f000000000343013f000000000332016f0000000102100210000000000123019f000000000010041b0000000001000019000002070001042e00000204002104230000000102000039000000000001042d0000000002000019000000000001042d0000020600000432000002070001042e000002080001043000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000ffffffff000000000000000000000000000000000000000000000000ffffffffffffffff80000000000000000000000000000000000000000000000000000000000000000200000000000000000000000000000000000020000000000000000000000000000000020000000000000000000000000000004000000100000000000000000000000000000000000000000000000000000000000000000000000000cfae321700000000000000000000000000000000000000000000000000000000a4136862290decd9548b62a8d60345a988386fc84ba6bc95484008f6362f93160ef3e5634e487b71000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000024000000000000000000000000000000000000000000000000000000000000000000000000000000000000000049640b54fe6c32c3d2b931a12d0e92ca2c903f61744f706361c28dd6cf0a568a \ No newline at end of file diff --git a/validium_mode_example/Greeter.sol b/validium_mode_example/Greeter.sol new file mode 100644 index 000000000000..7208f4c1326b --- /dev/null +++ b/validium_mode_example/Greeter.sol @@ -0,0 +1,18 @@ +//SPDX-License-Identifier: Unlicense +pragma solidity ^0.8.8; + +contract Greeter { + string private greeting; + + constructor(string memory _greeting) { + greeting = _greeting; + } + + function greet() public view returns (string memory) { + return greeting; + } + + function setGreeting(string memory _greeting) public { + greeting = _greeting; + } +} diff --git a/validium_mode_example/IERC20.sol b/validium_mode_example/IERC20.sol new file mode 100644 index 000000000000..2693a9f9ba15 --- /dev/null +++ b/validium_mode_example/IERC20.sol @@ -0,0 +1,81 @@ +// SPDX-License-Identifier: MIT + +pragma solidity >=0.8.0; + +/** + * @dev Interface of the ERC20 standard as defined in the EIP. + */ +interface IERC20 { + /** + * @dev Returns the amount of tokens in existence. + */ + function totalSupply() external view returns (uint256); + + /** + * @dev Returns the amount of tokens owned by `account`. + */ + function balanceOf(address account) external view returns (uint256); + + /** + * @dev Moves `amount` tokens from the caller's account to `recipient`. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transfer(address recipient, uint256 amount) external returns (bool); + + /** + * @dev Returns the remaining number of tokens that `spender` will be + * allowed to spend on behalf of `owner` through {transferFrom}. This is + * zero by default. + * + * This value changes when {approve} or {transferFrom} are called. + */ + function allowance(address owner, address spender) external view returns (uint256); + + /** + * @dev Sets `amount` as the allowance of `spender` over the caller's tokens. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * IMPORTANT: Beware that changing an allowance with this method brings the risk + * that someone may use both the old and the new allowance by unfortunate + * transaction ordering. One possible solution to mitigate this race + * condition is to first reduce the spender's allowance to 0 and set the + * desired value afterwards: + * https://github.com/ethereum/EIPs/issues/20#issuecomment-263524729 + * + * Emits an {Approval} event. + */ + function approve(address spender, uint256 amount) external returns (bool); + + /** + * @dev Moves `amount` tokens from `sender` to `recipient` using the + * allowance mechanism. `amount` is then deducted from the caller's + * allowance. + * + * Returns a boolean value indicating whether the operation succeeded. + * + * Emits a {Transfer} event. + */ + function transferFrom( + address sender, + address recipient, + uint256 amount + ) external returns (bool); + + /** + * @dev Emitted when `value` tokens are moved from one account (`from`) to + * another (`to`). + * + * Note that `value` may be zero. + */ + event Transfer(address indexed from, address indexed to, uint256 value); + + /** + * @dev Emitted when the allowance of a `spender` for an `owner` is set by + * a call to {approve}. `value` is the new allowance. + */ + event Approval(address indexed owner, address indexed spender, uint256 value); +} diff --git a/validium_mode_example/IERC20Metadata.sol b/validium_mode_example/IERC20Metadata.sol new file mode 100644 index 000000000000..1846275af4b3 --- /dev/null +++ b/validium_mode_example/IERC20Metadata.sol @@ -0,0 +1,27 @@ +// SPDX-License-Identifier: MIT + +pragma solidity >=0.8.0; + +import "./IERC20.sol"; + +/** + * @dev Interface for the optional metadata functions from the ERC20 standard. + * + * _Available since v4.1._ + */ +interface IERC20Metadata is IERC20 { + /** + * @dev Returns the name of the token. + */ + function name() external view returns (string memory); + + /** + * @dev Returns the symbol of the token. + */ + function symbol() external view returns (string memory); + + /** + * @dev Returns the decimals places of the token. + */ + function decimals() external view returns (uint8); +} diff --git a/validium_mode_example/README.md b/validium_mode_example/README.md new file mode 100644 index 000000000000..777696d4dc0f --- /dev/null +++ b/validium_mode_example/README.md @@ -0,0 +1,72 @@ +# Validium example + +In order to start the node as a validium and run the example follow the next steps. + +## Run the server + +To run this example we need to run the server in validium mode. In the `zksync-era` directory, you can run the following +command: + +```sh +zk && zk clean --all && zk init --validium-mode && zk server +``` + +> [!IMPORTANT] Make sure that the flag `--validium-mode` is present when initializing the server. + +This will set up the Ethereum node with the validium contracts, and also define an `env` var which the server will pick +up in order to run as a validium node. + +## Run the example + +In this example we're going to run some transactions. + +Once the server is running, run this command in other terminal: + +```sh +cargo run --release --bin zksync_full_stack +``` + +This test does the following: + +- Inits a wallet +- Deposits some funds into the wallet +- Deploys a sample ERC20 contract +- Query the contract for the token name and symbol +- Mint 100000 tokens into the address `CD2a3d9F938E13CD947Ec05AbC7FE734Df8DD826` +- Transfer 1000 tokens from `CD2a3d9F938E13CD947Ec05AbC7FE734Df8DD826` to `bBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB` + +## Logs and prints + +- For each transaction, we use the rpc client to query the transaction details and print them out. The following fields + are printed: + - `Transaction hash`: The hash of the transaction + - `Transaction gas used`: The gas used to perform this transaction. + - `L2 fee`: The total cost of this transaction. + +## Example output + +You will have an output similar to this one: + +``` +Deposit transaction hash: 0x77f378f1857ad7ff8c1041d2ce0f7f167587a90a19f9fd923c9ea91fbdf37650 +Deploy +Contract address: 0x4b5df730c2e6b28e17013a1485e5d9bc41efe021 +Transaction hash 0xe08786e302027040056555bdba6e0462fdee56768d982485d80f732043013bb5 +Transaction gas used 161163 +L2 fee: 40290750000000 + +Mint +Transaction hash 0x2f5b565959c8c5ffe320a364df27f4de451ed93ee6344a838f2212397da7fe5f +Transaction gas used 124046 +L2 fee: 31011500000000 +L1 max fee per gas: 1200000011 + +Transfer 1000 +Transaction hash 0x7cfadf74a5fa571ed9e2f1a115edc62f8db913d61d387177b7b07e2cb270af75 +Transaction gas used 125466 +L2 fee: 31366500000000 +L1 max fee per gas: 1000000010 +``` + +> [!NOTE] You can observe how the different fields evolve depending on the operation. The `transaction hash` is a +> changing field. diff --git a/validium_mode_example/src/main.rs b/validium_mode_example/src/main.rs new file mode 100644 index 000000000000..e290e4d9cd82 --- /dev/null +++ b/validium_mode_example/src/main.rs @@ -0,0 +1,269 @@ +use std::{str::FromStr, time::Duration}; + +use colored::Colorize; +use ethers::{abi::Abi, providers::Http, utils::parse_units}; +use loadnext::config::LoadtestConfig; +use tokio::time::sleep; +use zksync_web3_decl::{ + jsonrpsee::http_client::HttpClientBuilder, + namespaces::{EthNamespaceClient, ZksNamespaceClient}, +}; +use zksync_web3_rs::{ + eip712::Eip712TransactionRequest, + providers::{Middleware, Provider}, + signers::{LocalWallet, Signer}, + zks_provider::ZKSProvider, + zks_wallet::{DeployRequest, DepositRequest}, + ZKSWallet, +}; + +static ERA_PROVIDER_URL: &str = "http://127.0.0.1:3050"; +static PRIVATE_KEY: &str = "7726827caac94a7f9e1b160f7ea819f172f7b6f9d2a97f992c38edeab82d4110"; + +static CONTRACT_BIN: &str = include_str!("../ERC20.bin"); +static CONTRACT_ABI: &str = include_str!("../ERC20.abi"); + +static L1_URL: &str = "http://localhost:8545"; + +#[tokio::main(flavor = "current_thread")] +async fn main() { + let l1_provider = + Provider::::try_from(L1_URL).expect("Could not instantiate L1 Provider"); + let zk_wallet = { + let era_provider = Provider::try_from(ERA_PROVIDER_URL).unwrap(); + + let chain_id = era_provider.get_chainid().await.unwrap(); + let l2_wallet = LocalWallet::from_str(PRIVATE_KEY) + .unwrap() + .with_chain_id(chain_id.as_u64()); + ZKSWallet::new( + l2_wallet, + None, + Some(era_provider.clone()), + Some(l1_provider.clone()), + ) + .unwrap() + }; + + let config = LoadtestConfig::from_env() + .expect("Config parameters should be loaded from env or from default values"); + + let l1_rpc_client = HttpClientBuilder::default() + .build(config.l1_rpc_address) + .unwrap(); + let l2_rpc_client = HttpClientBuilder::default() + .build(config.l2_rpc_address) + .unwrap(); + + let deposit_transaction_hash = { + let amount = parse_units("11", "ether").unwrap(); + let request = DepositRequest::new(amount.into()); + zk_wallet + .deposit(&request) + .await + .expect("Failed to perform deposit transaction") + }; + println!(); + println!("Deposit transaction hash: {:?}", deposit_transaction_hash); + + // Deploy contract: + let contract_address = { + // Read both files from disk: + let abi = Abi::load(CONTRACT_ABI.as_bytes()).unwrap(); + let contract_bin = hex::decode(CONTRACT_BIN).unwrap().to_vec(); + + // DeployRequest sets the parameters for the constructor call and the deployment transaction. + let request = DeployRequest::with( + abi, + contract_bin, + vec!["ToniToken".to_owned(), "teth".to_owned()], + ) + .from(zk_wallet.l2_address()); + + let eip712_request: Eip712TransactionRequest = request.clone().try_into().unwrap(); + println!("{}", "Deploy".bright_magenta()); + + let transaction_receipt = zk_wallet + .get_era_provider() + .unwrap() + .clone() + .send_transaction_eip712(&zk_wallet.l2_wallet, eip712_request) + .await + .unwrap() + .await + .unwrap() + .unwrap(); + + let address = transaction_receipt.contract_address.unwrap(); + println!("Contract address: {:#?}", address); + + let transaction_hash_deploy = transaction_receipt.transaction_hash; + let transaction_hash_formatted_deploy = + format!("{:#?}", transaction_receipt.transaction_hash); + println!("Transaction hash {}", transaction_hash_formatted_deploy); + let transaction_gas_used_formatted_deploy = + format!("{:#?}", transaction_receipt.gas_used.unwrap()); + println!( + "Transaction gas used {}", + transaction_gas_used_formatted_deploy.cyan() + ); + let l2_transaction_deploy = { + loop { + let l2_transaction = l2_rpc_client + .get_transaction_details(transaction_hash_deploy) + .await + .unwrap() + .unwrap(); + + if l2_transaction.eth_commit_tx_hash.is_some() { + break l2_transaction.clone(); + } + + sleep(Duration::from_secs(1)).await; + } + }; + + let l2_tx_fee_formatted_deploy = format!("{:#?}", l2_transaction_deploy.fee); + println!("L2 fee: {}", l2_tx_fee_formatted_deploy.green()); + + address + }; + println!(); + + println!("{}", "Mint".bright_magenta()); + let receipt_mint = zk_wallet + .get_era_provider() + .unwrap() + .clone() + .send_eip712( + &zk_wallet.l2_wallet, + contract_address, + "_mint(address, uint256)", + Some( + [ + "CD2a3d9F938E13CD947Ec05AbC7FE734Df8DD826".into(), + "100000".into(), + ] + .into(), + ), + None, + ) + .await + .unwrap() + .await + .unwrap() + .unwrap(); + + let transaction_hash_mint = receipt_mint.transaction_hash; + let transaction_hash_formatted_mint = format!("{:#?}", receipt_mint.transaction_hash); + println!("Transaction hash {}", transaction_hash_formatted_mint); + let transaction_gas_used_formatted_mint = format!("{:#?}", receipt_mint.gas_used.unwrap()); + println!( + "Transaction gas used {}", + transaction_gas_used_formatted_mint.cyan() + ); + let l2_transaction_mint = { + loop { + let l2_transaction = l2_rpc_client + .get_transaction_details(transaction_hash_mint) + .await + .unwrap() + .unwrap(); + + if l2_transaction.eth_commit_tx_hash.is_some() { + break l2_transaction.clone(); + } + + sleep(Duration::from_secs(1)).await; // Adjust the duration as needed + } + }; + + let l2_tx_fee_formatted_mint = format!("{:#?}", l2_transaction_mint.fee); + println!("L2 fee: {}", l2_tx_fee_formatted_mint.green()); + + let l1_transaction_transfer = l1_rpc_client + .get_transaction_by_hash(l2_transaction_mint.eth_commit_tx_hash.unwrap()) + .await + .unwrap() + .unwrap(); + + let l1_max_fee_per_gas_mint = l1_transaction_transfer.max_fee_per_gas.unwrap(); + let l1_max_fee_per_gas_formatted_mint = format!("{:#?}", l1_max_fee_per_gas_mint); + println!( + "L1 max fee per gas: {}", + l1_max_fee_per_gas_formatted_mint.cyan() + ); + println!(); + + let values: Vec<&str> = vec!["1000"]; + + for &value in &values { + println!("Transfer {}", value.bright_magenta()); + let receipt_transfer = zk_wallet + .get_era_provider() + .unwrap() + .clone() + .send_eip712( + &zk_wallet.l2_wallet, + contract_address, + "_transfer(address, address, uint256)", + Some( + [ + "CD2a3d9F938E13CD947Ec05AbC7FE734Df8DD826".into(), + "bBbBBBBbbBBBbbbBbbBbbbbBBbBbbbbBbBbbBBbB".into(), + value.into(), + ] + .into(), + ), + None, + ) + .await + .unwrap() + .await + .unwrap() + .unwrap(); + + let transaction_hash_transfer = receipt_transfer.transaction_hash; + let transaction_hash_formatted_transfer = + format!("{:#?}", receipt_transfer.transaction_hash); + println!("Transaction hash {}", transaction_hash_formatted_transfer); + let transaction_gas_used_formatted_transfer = + format!("{:#?}", receipt_transfer.gas_used.unwrap()); + println!( + "Transaction gas used {}", + transaction_gas_used_formatted_transfer.cyan() + ); + let l2_transaction_transfer = { + loop { + let l2_transaction = l2_rpc_client + .get_transaction_details(transaction_hash_transfer) + .await + .unwrap() + .unwrap(); + + if l2_transaction.eth_commit_tx_hash.is_some() { + break l2_transaction.clone(); + } + + sleep(Duration::from_secs(1)).await; // Adjust the duration as needed + } + }; + + let l2_tx_fee_formatted_transfer = format!("{:#?}", l2_transaction_transfer.fee); + println!("L2 fee: {}", l2_tx_fee_formatted_transfer.green()); + + let l1_transaction_transfer = l1_rpc_client + .get_transaction_by_hash(l2_transaction_transfer.eth_commit_tx_hash.unwrap()) + .await + .unwrap() + .unwrap(); + + let l1_max_fee_per_gas_transfer = l1_transaction_transfer.max_fee_per_gas.unwrap(); + let l1_max_fee_per_gas_formatted_transfer = format!("{:#?}", l1_max_fee_per_gas_transfer); + println!( + "L1 max fee per gas: {}", + l1_max_fee_per_gas_formatted_transfer.cyan() + ); + println!(); + } +}