Contract con_lamden_link_v1


Contract Code

1
2 I = importlib
3
4 # Enforceable interface
5 token_interface = [
6 I.Func('transfer', args=('amount', 'to')),
7 I.Func('mint', args=('amount', 'to')),
8 I.Func('approve', args=('amount', 'to')),
9 I.Func('transfer_from', args=('amount', 'to', 'main_account'))
10 ]
11
12 supported_tokens = Hash()
13 nonces = Hash(default_value=0)
14 proofs = Hash()
15
16 # LST002
17 metadata = Hash()
18
19 @construct
20 def seed():
21 # LST002
22 metadata['operator'] = ctx.caller
23
24 # LST002
25 @export
26 def change_metadata(key: str, value: Any):
27 assert ctx.caller == metadata['operator'], 'Only operator can set metadata!'
28 metadata[key] = value
29
30 def left_pad(s: str):
31 while len(s) < 64:
32 s = f'0{s}'
33
34 if len(s) > 64:
35 s = s[:64]
36
37 return s
38
39 def unpack_uint256(uint: str, decimals: int):
40 i = int(uint, 16)
41 reduced_i = i / (10 ** decimals)
42 return reduced_i
43
44 def pack_amount(amount: float, decimals: int):
45 i = int(amount * (10 ** decimals))
46 h = hex(i)[2:]
47 return left_pad(h)
48
49 def pack_eth_address(address: str):
50 assert address.startswith('0x'), 'Invalid Ethereum prefix'
51 a = address[2:]
52
53 assert len(a) == 40, 'Invalid address length'
54
55 int(a, 16) # Throws error if not hex string
56
57 return left_pad(a)
58
59 def pack_int(i: int):
60 i = int(i)
61 h = hex(i)[2:]
62 return left_pad(h)
63
64 @export
65 def mint(ethereum_contract: str, amount: str, lamden_wallet: str):
66 assert ctx.caller == metadata['operator'], 'Only operator can call! Current caller is {}, operator should be {}'.format(ctx.caller, metadata['operator'])
67 assert supported_tokens[ethereum_contract] is not None, 'Invalid Ethereum Token!'
68
69 decimals = supported_tokens[ethereum_contract, 'decimals']
70
71 assert decimals is not None, 'Unexpected decimal error'
72
73 unpacked_amount = unpack_uint256(amount, decimals)
74
75 token = I.import_module(supported_tokens[ethereum_contract])
76
77 assert I.enforce_interface(token, token_interface), 'Invalid token interface!'
78
79 token.mint(amount=unpacked_amount, to=lamden_wallet)
80
81 @export
82 def burn(ethereum_contract: str, ethereum_address: str, amount: float):
83 assert supported_tokens[ethereum_contract] is not None, 'Invalid Ethereum Token!'
84
85 token = I.import_module(supported_tokens[ethereum_contract])
86
87 assert I.enforce_interface(token, token_interface), 'Invalid token interface!'
88
89 token.transfer_from(amount=amount, to=ctx.this, main_account=ctx.caller)
90
91 packed_token = pack_eth_address(ethereum_contract)
92 packed_amount = pack_amount(amount, supported_tokens[ethereum_contract, 'decimals'])
93 packed_nonce = pack_int(nonces[ethereum_address] + 1)
94 packed_address = pack_eth_address(ethereum_address)
95
96 nonces[ethereum_address] += 1
97
98 abi = packed_token + packed_amount + packed_nonce + packed_address
99 return abi
100
101 @export
102 def add_token(ethereum_contract: str, lamden_contract: str, decimals: int):
103 assert supported_tokens[ethereum_contract] is None, 'Token already supported'
104 assert ctx.caller == metadata['operator'], 'Only operator can call!'
105
106 token = I.import_module(lamden_contract)
107
108 assert I.enforce_interface(token, token_interface), 'Invalid token interface!'
109
110 supported_tokens[ethereum_contract] = lamden_contract
111 supported_tokens[ethereum_contract, 'decimals'] = decimals
112
113 @export
114 def post_proof(hashed_abi: str, signed_abi: str):
115 assert ctx.caller == metadata['operator'], 'Only operator can call!'
116 proofs[hashed_abi] = signed_abi

Byte Code

e30000000000000000000000000800000040000000733e01000065005a0165016a026400643064038d0265016a026404643164038d0265016a026405643264038d0265016a026406643364038d0267045a03650464086409640a8d025a056504640b6408640c640d8d035a0665046408640e640a8d025a0765046408640f640a8d025a086410641184005a09650a64088301650b650c64129c0264136414840483015a0d650b64159c016416641784045a0e650b650f64189c026419641a84045a106511650f641b9c02641c641d84045a12650b641e9c01641f642084045a13650f64219c016422642384045a14650a64088301650b650b650b64249c0364256404840483015a15650a64088301650b650b651164269c0364276428840483015a16650a64088301650b650b650f64299c03642a642b840483015a17650a64088301650b650b642c9c02642d642e840483015a18642f53002934da087472616e73666572da06616d6f756e74da02746f2901da0461726773da046d696e74da07617070726f7665da0d7472616e736665725f66726f6dda0c6d61696e5f6163636f756e74da12636f6e5f6c616d64656e5f6c696e6b5f7631da10737570706f727465645f746f6b656e732902da08636f6e7472616374da046e616d65e900000000da066e6f6e6365732903da0d64656661756c745f76616c7565720b000000720c000000da0670726f6f6673da086d65746164617461630000000000000000000000000300000043000000730e00000074006a01740264013c006400530029024eda086f70657261746f722903da03637478da0663616c6c6572da0a5f5f6d65746164617461a90072160000007216000000da00da045f5f5f5f0c0000007302000000000172180000002902da036b6579da0576616c7565630200000000000000020000000300000043000000732200000074006a017402640119006b02731674036402830182017c0174027c003c006400530029034e72120000007a1f4f6e6c79206f70657261746f722063616e20736574206d65746164617461212904721300000072140000007215000000da0e417373657274696f6e4572726f7229027219000000721a000000721600000072160000007217000000da0f6368616e67655f6d65746164617461100000007306000000000210010601721c0000002901da01736301000000000000000100000003000000430000007338000000781a74007c00830164016b00721a64027c009b009d027d007102570074007c00830164016b0472347c0064006401850219007d007c00530029034ee940000000da01302901da036c656e2901721d000000721600000072160000007217000000da0a5f5f6c6566745f70616417000000730a00000000010e010e010c010c0172210000002902da0475696e74da08646563696d616c73630200000000000000040000000300000043000000731a00000074007c00640183027d027c0264027c0113001b007d037c03530029034ee910000000e90a0000002901da03696e74290472220000007223000000da0169da09726564756365645f69721600000072160000007217000000da105f5f756e7061636b5f75696e743235361f000000730600000000010a010c017229000000290272020000007223000000630200000000000000040000000400000043000000732800000074007c0064017c011300140083017d0274017c02830164026400850219007d0374027c038301530029034e7225000000e90200000029037226000000da0368657872210000002904720200000072230000007227000000da0168721600000072160000007217000000da0d5f5f7061636b5f616d6f756e74250000007306000000000110011001722d0000002901da076164647265737363010000000000000002000000030000004300000073440000007c006a0064018301731274016402830182017c0064036400850219007d0174027c01830164046b027332740164058301820174037c0164068302010074047c018301530029074eda0230787a17496e76616c696420457468657265756d20707265666978722a000000e9280000007a16496e76616c69642061646472657373206c656e67746872240000002905da0a73746172747377697468721b0000007220000000722600000072210000002902722e000000da0161721600000072160000007217000000da125f5f7061636b5f6574685f616464726573732b000000730a000000000112010c0114010a01723300000029017227000000630100000000000000020000000300000043000000732000000074007c0083017d0074017c00830164016400850219007d0174027c018301530029024e722a00000029037226000000722b000000722100000029027227000000722c000000721600000072160000007217000000da0a5f5f7061636b5f696e7433000000730600000000010801100172340000002903da11657468657265756d5f636f6e74726163747202000000da0d6c616d64656e5f77616c6c6574630300000000000000060000000500000043000000739200000074006a017402640119006b027324740364026a0474006a0174026401190083028301820174057c00190064006b097338740364038301820174057c006404660219007d037c0364006b097354740364058301820174067c017c0383027d0474076a0874057c00190083017d0574076a097c05740a8302738074036406830182017c056a0b7c047c0264078d0201006400530029084e72120000007a434f6e6c79206f70657261746f722063616e2063616c6c212043757272656e742063616c6c6572206973207b7d2c206f70657261746f722073686f756c64206265207b7d7a17496e76616c696420457468657265756d20546f6b656e2172230000007a18556e657870656374656420646563696d616c206572726f727a18496e76616c696420746f6b656e20696e7465726661636521290272020000007203000000290c721300000072140000007215000000721b000000da06666f726d6174da125f5f737570706f727465645f746f6b656e737229000000da0149da0d696d706f72745f6d6f64756c65da11656e666f7263655f696e74657266616365da0f746f6b656e5f696e74657266616365720500000029067235000000720200000072360000007223000000da0f756e7061636b65645f616d6f756e74da05746f6b656e7216000000721600000072170000007205000000390000007318000000000210010401100106010e010c0110010a010e010e01060129037235000000da10657468657265756d5f61646472657373720200000063030000000000000009000000050000004300000073a000000074007c00190064006b097314740164018301820174026a0374007c00190083017d0374026a047c0374058302733674016402830182017c036a067c0274076a0874076a0964038d030100740a7c0083017d04740b7c0274007c0064046602190083027d05740c740d7c0119006405170083017d06740a7c0183017d07740d7c01050019006405370003003c007c047c0517007c0617007c0717007d087c08530029064e7a17496e76616c696420457468657265756d20546f6b656e217a18496e76616c696420746f6b656e20696e746572666163652129037202000000720300000072080000007223000000e901000000290e7238000000721b0000007239000000723a000000723b000000723c00000072070000007213000000da047468697372140000007233000000722d0000007234000000da085f5f6e6f6e63657329097235000000723f0000007202000000723e000000da0c7061636b65645f746f6b656eda0d7061636b65645f616d6f756e74da0c7061636b65645f6e6f6e6365da0e7061636b65645f61646472657373da03616269721600000072160000007217000000da046275726e49000000731c000000000206010e010e010e0106011401080106010c011001080110011001724800000029037235000000da0f6c616d64656e5f636f6e74726163747223000000630300000000000000040000000400000043000000736000000074007c00190064006b087314740164018301820174026a037404640219006b02732a740164038301820174056a067c0183017d0374056a077c0374088302734874016404830182017c0174007c003c007c0274007c00640566023c006400530029064e7a17546f6b656e20616c726561647920737570706f7274656472120000007a174f6e6c79206f70657261746f722063616e2063616c6c217a18496e76616c696420746f6b656e20696e7465726661636521722300000029097238000000721b0000007213000000721400000072150000007239000000723a000000723b000000723c0000002904723500000072490000007223000000723e000000721600000072160000007217000000da096164645f746f6b656e5b0000007310000000000206010e0116010a010e0106010801724a0000002902da0a6861736865645f616269da0a7369676e65645f616269630200000000000000020000000300000043000000732200000074006a017402640119006b02731674036402830182017c0174047c003c006400530029034e72120000007a174f6e6c79206f70657261746f722063616e2063616c6c212905721300000072140000007215000000721b000000da085f5f70726f6f66732902724b000000724c000000721600000072160000007217000000da0a706f73745f70726f6f6667000000730400000000021601724e0000004e29027202000000720300000029027202000000720300000029027202000000720300000029037202000000720300000072080000002919da09696d706f72746c69627239000000da0446756e63723c000000da044861736872380000007242000000724d00000072150000007218000000da085f5f6578706f7274da03737472da03416e79721c000000722100000072260000007229000000da05666c6f6174722d0000007233000000723400000072050000007248000000724a000000724e0000007216000000721600000072160000007217000000da083c6d6f64756c653e0100000073300000000401120116010c01040108010e010c010c030804060112060e08100610060e080e060601140f060114110601140b0601