/ data / aecore / .lima / Readme.md
Readme.md
 1  # Token migration contract
 2  
 3  In the Lima hard-fork the remaining (frozen) Aeternity tokens from the Ethereum
 4  ERC20 contract are put into a contract and can be retreived by the entity
 5  holding the correct Ethereum private key. This contract is added to chain as
 6  part of the hard-fork, and the contract is also funded as part of the
 7  hard-fork. Here we describe how we prepare the data (the `contracts.json` file)
 8  that is used during the hard-fork. The `.json`-file has the following format
 9  and constraints (`apps/aecore/src/aec_fork_block_settings.erl`):
10  
11  ```
12  %%% { <API encoded pubkey for contract> : { "amount" : <integer>,
13  %%%                                         "vm_version" : <integer>,
14  %%%                                         "abi_version" : <integer>,
15  %%%                                         "nonce" : <integer>
16  %%%                                         "code" : <API encoded contract byte array>
17  %%%                                         "call_data" : <API encoded contract byte array>
18  %%%                                       }
19  %%% ...
20  %%% }
21  %%%
22  %%% The locked token account will be the owner of the contracts.
23  %%% The nonces must correspond to the nonces of the owner account.
24  %%% The nonces must be consecutive (but not necessarity ordered)
25  %%% The pubkey of the contract must correspond to the computed pubkey
26  %%%    (based on owner account and nonce). This is mostly a fail safe to ensure
27  %%%    that the contract pubkey is visible in the file.
28  ```
29  
30  Since this is the first contract to be added by this mechanism, the nonce to be
31  used is `1` and we can compute the contract pubkey using Erlang:
32  
33  ```
34  25> Locked = aec_governance:locked_coins_holder_account(), Nonce = 1.
35  1
36  26> CtPK = aect_contracts:compute_contract_pubkey(Locked, Nonce).
37  <<84,180,196,235,185,254,235,68,37,168,101,128,127,111,97,
38    136,141,11,134,251,228,200,73,71,175,98,22,115,172,...>>
39  27> aeser_api_encoder:encode(contract_pubkey, CtPK).
40  <<"ct_eJhrbPPS4V97VLKEVbSCJFpdA4uyXiZujQyLqMFoYV88TzDe6">>
41  ```
42  
43  Then we need to compute the total sum of tokens. The final list of accounts
44  that has not migrated their tokens is in `test/json/contracts_accounts.json`.
45  The sum of the tokens is:
46  
47  ```
48  79> mtree:total_sum_from_json("../test/json/contracts_accounts.json").
49  29622067581238053773524138
50  ```
51  
52  We also need the root-hash of the Merkle tree (the tree contains all the
53  Ethereum accounts and their respective balances).
54  
55  ```
56  80> BigT = mtree:tree_from_json("../test/json/contracts_accounts.json"), ok.
57  ok
58  81> mtree:root_hash(BigT).
59  "E4DBC69BF2783B81B0423DA3F5B684C1D37CCFAE798474525C4001DB42C67669"
60  ```
61  
62  Finally we need to compile the contract [available
63  HERE](test/contracts/token_migration.aes), and the contract init call data:
64  
65  ```
66  aeternity : ls -l test/contracts/token_migration.aes
67  -rw-r--r--  1 hans  staff  3966 Sep 27 10:39 test/contracts/token_migration.aes
68  aeternity : md5 test/contracts/token_migration.aes
69  MD5 (test/contracts/token_migration.aes) = 56ead7528cb20700e148566e5683b5c0
70  aeternity : md5 ../aesophia_cli/priv/bin/v4.0.0-rc5/aesophia_cli
71  MD5 (../aesophia_cli/priv/bin/v4.0.0-rc5/aesophia_cli) = 39ae10aa26838dc99f5caae5f43d98ff
72  aeternity : ../aesophia_cli/priv/bin/v4.0.0-rc5/aesophia_cli test/contracts/token_migration.aes
73  Bytecode:
74  cb_+QP9RgOguo6qpyu/hfk5d+qq/tgbo35YmOc3e32WGzPH9WKYCUnAuQPLuQL0/gYNP1AANwUHRwAHJ3eXbwEHfAQCBwwgDAOBUGFzc2VkIEFFIGFkZHJlc3MgaXMgbm90IHBheWFibGX7ABoCb4ImzzwGAgI+CAI7ADogAjoOBGkZRXRoZXJldW0gU2lnbmVkIE1lc3NhZ2U6CgwBCBsIBAIDEeg39H8aAggIPggcHhoCCgwCCgIDEcnWapQmAAcMGgwDvVRoaXMgYWNjb3VudCBoYXMgYWxyZWFkeSB0cmFuc2ZlcnJlZCBpdHMgdG9rZW5z+wAaAm+CJs8MAQYMAQQMAQAMAgoCAxFdcNL1BwwYDAPFRnJvbSBwcm92aWRlZCBkYXRhLCBjYW5ub3QgYmUgZ2VuZXJhdGVkIHNhbWUgcm9vdPsAGgJvgibPDAEADAECZQAoLAKCEAwCgikMAhoCFCguFgQULegWCj8MAhQpDAQaAoIMAgoMAQIMAQBE/BMGAAYCAxFlpeAPGgJvgibPKCwCggAMAz8GAxQMAz8GAw4MA6FGYWlsZWQgdG8gcmVjb3ZlciBhZGRyZXNzLCBiYWQgc2lnbmF0dXJl+wBGOgoIAEAICjoMCTBYBgMIDAM/BgME/kTWRB8ANwJ3BzcADAEADAECKgAnDAYaAoIBAz/+XXDS9QA3BHcHByd3FzsEAjoMBTo6BgAAGwgAQAAMAQQMAQYCAxHsL+O+GgIEKCwAgiAIBAD+ZaXgDwI3AYcBNwN3RwAHNwBGNAAERjQAAgwDnwGBR4YJ0hFJn+CFQlrEPeWHXqVaT+74Y8OnTxa1W2+3OL1GNAAAYwABAz/+tIwWhAA3AAdTAAD+u6I84gA3AHcoLACCAP7J1mqUADcBdxcoLASCLxAAAP7YuSNvADcABygsAoIA/ug39H8CNwKXQJdvAYcCNwA3AZcofxQAAgD+7C/jvgI3Ayd3B3d3MwQABwwMNQYAADYGAgAYNAIEIDACBwwKOiQEAAYDBhoCBBsIBEABBBoJAAIXNQICBAYDAAA6GAAEBgMGAQEEuM8vChEGDT9QHW1pZ3JhdGURRNZEHxFpbml0EV1w0vVhY29udGFpbmVkX2luX21lcmtsZV90cmVlEWWl4A8tQ2hhaW4uZXZlbnQRtIwWhB1iYWxhbmNlEbuiPOIlcm9vdF9oYXNoEcnWapQtaXNfbWlncmF0ZWQR2Lkjb0FtaWdyYXRpb25zX2NvdW50Eeg39H9pLlRva2VuTWlncmF0aW9uLmdldF9zaWduZXIR7C/jvnkuVG9rZW5NaWdyYXRpb24uY2FsY3VsYXRlX3Jvb3SCLwCJNC4wLjAtcmM1AIUFMq4=
75  aeternity : ../aesophia_cli/priv/bin/v4.0.0-rc5/aesophia_cli --create_calldata test/contracts/token_migration.aes --calldata_fun init --calldata_args "\"E4DBC69BF2783B81B0423DA3F5B684C1D37CCFAE798474525C4001DB42C67669\", 0"
76  Calldata:
77  cb_KxFE1kQfKwEARTREQkM2OUJGMjc4M0I4MUIwNDIzREEzRjVCNjg0QzFEMzdDQ0ZBRTc5ODQ3NDUyNUM0MDAxREI0MkM2NzY2OQDtuA/R
78  ```
79  
80  The resulting data is then:
81  ```
82  {
83      "ct_eJhrbPPS4V97VLKEVbSCJFpdA4uyXiZujQyLqMFoYV88TzDe6" :
84          { "amount"      : 29622067581238053773524138,
85            "vm_version"  : 5,
86            "abi_version" : 3,
87            "nonce"       : 1,
88            "code"        : "cb_+QP9RgOguo6qpyu/hfk5d+qq/tgbo35YmOc3e32WGzPH9WKYCUnAuQPLuQL0/gYNP1AANwUHRwAHJ3eXbwEHfAQCBwwgDAOBUGFzc2VkIEFFIGFkZHJlc3MgaXMgbm90IHBheWFibGX7ABoCb4ImzzwGAgI+CAI7ADogAjoOBGkZRXRoZXJldW0gU2lnbmVkIE1lc3NhZ2U6CgwBCBsIBAIDEeg39H8aAggIPggcHhoCCgwCCgIDEcnWapQmAAcMGgwDvVRoaXMgYWNjb3VudCBoYXMgYWxyZWFkeSB0cmFuc2ZlcnJlZCBpdHMgdG9rZW5z+wAaAm+CJs8MAQYMAQQMAQAMAgoCAxFdcNL1BwwYDAPFRnJvbSBwcm92aWRlZCBkYXRhLCBjYW5ub3QgYmUgZ2VuZXJhdGVkIHNhbWUgcm9vdPsAGgJvgibPDAEADAECZQAoLAKCEAwCgikMAhoCFCguFgQULegWCj8MAhQpDAQaAoIMAgoMAQIMAQBE/BMGAAYCAxFlpeAPGgJvgibPKCwCggAMAz8GAxQMAz8GAw4MA6FGYWlsZWQgdG8gcmVjb3ZlciBhZGRyZXNzLCBiYWQgc2lnbmF0dXJl+wBGOgoIAEAICjoMCTBYBgMIDAM/BgME/kTWRB8ANwJ3BzcADAEADAECKgAnDAYaAoIBAz/+XXDS9QA3BHcHByd3FzsEAjoMBTo6BgAAGwgAQAAMAQQMAQYCAxHsL+O+GgIEKCwAgiAIBAD+ZaXgDwI3AYcBNwN3RwAHNwBGNAAERjQAAgwDnwGBR4YJ0hFJn+CFQlrEPeWHXqVaT+74Y8O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