Contract con_network_bridge_concept_fixed


Contract Code


  
1 I = importlib
2
3 deposits = Hash(default_value=0)
4 withdraws = Hash(default_value=0)
5 active = Variable()
6 bridge_token = Variable()
7 bridge_op = Variable()
8 contract_op = Variable()
9
10 @construct
11 def seed():
12 active.set(False)
13 bridge_token.set("con_lusd_lst001")
14 bridge_op.set("ff61544ea94eaaeb5df08ed863c4a938e9129aba6ceee5f31b6681bdede11b89")
15 contract_op.set("ff61544ea94eaaeb5df08ed863c4a938e9129aba6ceee5f31b6681bdede11b89")
16
17
18 @export
19 def set_active(state:bool):
20 assert ctx.caller == contract_op.get(), "Only the contract operator can change the active state"
21 active.set(state)
22
23
24 @export
25 def set_bridge_token(contract:str):
26 assert ctx.caller == contract_op.get(), "Only the contract operator can change the bridge token"
27 bridge_token.set(contract)
28
29
30 @export
31 def set_bridge_op(address:str):
32 assert ctx.caller == contract_op.get(), "Only the contract operator can change the bridge operator"
33 bridge_op.set(address)
34
35
36 @export
37 def deposit(amount:float):
38 assert active.get() == True, "The bridge is currently paused"
39 I.import_module(bridge_token.get()).transfer_from(
40 amount=amount,
41 to=ctx.this,
42 main_account=ctx.caller)
43 if deposits[ctx.caller] == 0:
44 deposits[ctx.caller] = {"time": now, "processed": False, "amount": amount}
45 else:
46 assert deposits[ctx.caller]["processed"] == True, "You have an already ongoing bridge request"
47 deposits[ctx.caller] = {"time": now, "processed": False, "amount": amount}
48
49
50 @export
51 def finish_deposit_bridge_request(request_address: str):
52 assert bridge_op.get() == ctx.caller, "Only the bridge operator address can finish a request"
53 deposit = deposits[request_address]
54
55 assert deposit["processed"] == False, "This request is already processed"
56 deposit["processed"] = True
57 deposits[request_address] = deposit
58
59
60 @export
61 def withdraw(amount:float):
62 assert active.get() == True, "The bridge is currently paused"
63 if withdraws[ctx.caller] == 0:
64 withdraws[ctx.caller] = {"time": now, "processed": False, "amount": amount}
65 else:
66 withdraws[ctx.caller] = {"time": now, "processed": False, "amount": amount}
67
68
69 @export
70 def finish_withdraw_bridge_request(request_address: str):
71 assert bridge_op.get() == ctx.caller, "Only the bridge operator address can finish a request"
72 withdraw = withdraws[request_address]
73
74 assert withdraw["processed"] == False, "This request is already processed"
75 I.import_module(bridge_token.get()).transfer(
76 amount=amount,
77 to=ctx.caller)
78 withdraw["processed"] = True
79 withdraw[request_address] = withdraw
80

Byte Code

e3000000000000000000000000050000004000000073f600000065005a01650264006401640264038d035a03650264006401640464038d035a0465056401640564068d025a0665056401640764068d025a0765056401640864068d025a0865056401640964068d025a09640a640b84005a0a650b64018301650c640c9c01640d640e840483015a0d650b64018301650e640f9c0164106411840483015a0f650b64018301650e64129c0164136414840483015a10650b64018301651164159c0164166417840483015a12650b64018301650e64189c016419641a840483015a13650b64018301651164159c01641b641c840483015a14650b64018301650e64189c01641d641e840483015a15641f53002920e900000000da20636f6e5f6e6574776f726b5f6272696467655f636f6e636570745f6669786564da086465706f736974732903da0d64656661756c745f76616c7565da08636f6e7472616374da046e616d65da09776974686472617773da06616374697665290272050000007206000000da0c6272696467655f746f6b656eda096272696467655f6f70da0b636f6e74726163745f6f70630000000000000000000000000200000043000000732c00000074006a0164018301010074026a0164028301010074036a0164038301010074046a016403830101006400530029044e46da0f636f6e5f6c7573645f6c7374303031da40666636313534346561393465616165623564663038656438363363346139333865393132396162613663656565356633316236363831626465646531316238392905da085f5f616374697665da03736574da0e5f5f6272696467655f746f6b656eda0b5f5f6272696467655f6f70da0d5f5f636f6e74726163745f6f70a90072130000007213000000da00da045f5f5f5f0f000000730c00000000010a010a0104010601040172150000002901da057374617465630100000000000000010000000200000043000000732400000074006a0174026a0383006b027316740464018301820174056a067c00830101006400530029024e7a364f6e6c792074686520636f6e7472616374206f70657261746f722063616e206368616e676520746865206163746976652073746174652907da03637478da0663616c6c65727212000000da03676574da0e417373657274696f6e4572726f72720e000000720f00000029017216000000721300000072130000007214000000da0a7365745f616374697665180000007306000000000210010601721b00000029017205000000630100000000000000010000000200000043000000732400000074006a0174026a0383006b027316740464018301820174056a067c00830101006400530029024e7a364f6e6c792074686520636f6e7472616374206f70657261746f722063616e206368616e6765207468652062726964676520746f6b656e29077217000000721800000072120000007219000000721a0000007210000000720f00000029017205000000721300000072130000007214000000da107365745f6272696467655f746f6b656e1f0000007306000000000210010601721c0000002901da0761646472657373630100000000000000010000000200000043000000732400000074006a0174026a0383006b027316740464018301820174056a067c00830101006400530029024e7a394f6e6c792074686520636f6e7472616374206f70657261746f722063616e206368616e67652074686520627269646765206f70657261746f7229077217000000721800000072120000007219000000721a0000007211000000720f0000002901721d000000721300000072130000007214000000da0d7365745f6272696467655f6f70260000007306000000000210010601721e0000002901da06616d6f756e74630100000000000000010000000500000043000000738400000074006a01830064016b027314740264028301820174036a0474056a01830083016a067c0074076a0874076a0964038d030100740a74076a09190064046b027254740b64057c0064069c03740a74076a093c006e2c740a74076a0919006407190064016b02736e7402640883018201740b64057c0064069c03740a74076a093c006400530029094e547a1e546865206272696467652069732063757272656e746c79207061757365642903721f000000da02746fda0c6d61696e5f6163636f756e747201000000462903da0474696d65da0970726f636573736564721f00000072230000007a2a596f75206861766520616e20616c7265616479206f6e676f696e67206272696467652072657175657374290c720e0000007219000000721a000000da0149da0d696d706f72745f6d6f64756c657210000000da0d7472616e736665725f66726f6d7217000000da04746869737218000000da0a5f5f6465706f73697473da036e6f772901721f000000721300000072130000007214000000da076465706f7369742d00000073140000000002140110010e010e01040110020c010e010401722a0000002901da0f726571756573745f61646472657373630100000000000000020000000300000043000000734600000074006a01830074026a036b027316740464018301820174057c0019007d017c016402190064036b027332740464048301820164057c0164023c007c0174057c003c006400530029064e7a354f6e6c792074686520627269646765206f70657261746f7220616464726573732063616e2066696e697368206120726571756573747223000000467a2154686973207265717565737420697320616c72656164792070726f6365737365645429067211000000721900000072170000007218000000721a00000072280000002902722b000000722a000000721300000072130000007214000000da1d66696e6973685f6465706f7369745f6272696467655f726571756573743c000000730c000000000206011001080114010801722c000000630100000000000000010000000400000043000000734c00000074006a01830064016b0273147402640283018201740374046a05190064036b027236740664047c0064059c03740374046a053c006e12740664047c0064059c03740374046a053c006400530029064e547a1e546865206272696467652069732063757272656e746c7920706175736564720100000046290372220000007223000000721f0000002907720e0000007219000000721a000000da0b5f5f7769746864726177737217000000721800000072290000002901721f000000721300000072130000007214000000da08776974686472617746000000730c000000000214010e01040110020401722e000000630100000000000000020000000400000043000000736000000074006a01830074026a036b027316740464018301820174057c0019007d017c016402190064036b027332740464048301820174066a0774086a01830083016a09740a74026a0364058d02010064067c0164023c007c017c017c003c006400530029074e7a354f6e6c792074686520627269646765206f70657261746f7220616464726573732063616e2066696e697368206120726571756573747223000000467a2154686973207265717565737420697320616c72656164792070726f6365737365642902721f000000722000000054290b7211000000721900000072170000007218000000721a000000722d000000722400000072250000007210000000da087472616e73666572721f0000002902722b000000722e000000721300000072130000007214000000da1e66696e6973685f77697468647261775f6272696467655f7265717565737451000000730e000000000206011001080114011a02080172300000004e2916da09696d706f72746c69627224000000da04486173687228000000722d000000da085661726961626c65720e0000007210000000721100000072120000007215000000da085f5f6578706f7274da04626f6f6c721b000000da03737472721c000000721e000000da05666c6f6174722a000000722c000000722e00000072300000007213000000721300000072130000007214000000da083c6d6f64756c653e010000007334000000040104010a0104010a010c0104010801040108010401080308090601100606011006060110060601100e060110090601100a0601