Contract con_ll_t00


Contract Code

1 I = importlib
2 lock_info = Hash()
3 lp_points = Hash(default_value=0)
4
5 @construct
6 def seed():
7 lp_points["con_stakeit", "28f7fa3ecbb7d794e623a6692f09a06a912f58ff478a44d034d174dd5e9fac9e"] = 100
8 lock_info["con_stakeit", "28f7fa3ecbb7d794e623a6692f09a06a912f58ff478a44d034d174dd5e9fac9e"] = {
9 "lock_date":datetime.datetime(2021,9,11,0,14,0),
10 "initial_amount": 100,
11 "amount": 100,
12 "unlock_date": datetime.datetime(2021,10,11,0,14,0),
13 "lock_ID":'eqweweghjghhghf'
14 }
15
16 @export
17 def lock_lp(contract: str, amount: float, lock_time: int): #calculate lock_time in seconds from frontend side
18 assert amount > 0, "negative value not allowed!"
19 assert lock_time > 0, "negative value not allowed!"
20 pairs = ForeignHash(foreign_contract='con_amm_v9', foreign_name='pairs')
21 #check if pair market exist
22 assert pairs[contract], f"{contract}-currency(TAU) pair does not exist!"
23 user = ctx.caller
24 lock_time = datetime.timedelta(seconds=lock_time)
25 today = now
26 unlock_date = today + lock_time
27 #check if date is beyond now
28 assert unlock_date > today, "invalid time!"
29 #transfer lp points from user to this contract
30 rswp = I.import_module('con_amm_v9')
31 rswp.transfer_liquidity_from(contract=contract, to=ctx.this, main_account=user, amount=amount)
32 lp_points[contract, user] += amount
33 #get id from hash
34 hashables = f"{contract}{user}{amount}{lock_time}{today}"
35 lock_id = hashlib.sha256(hashables)
36 #gather liquidity locking details
37 lock_info[contract, user] = {
38 "lock_date":today,
39 "initial_amount": amount,
40 "amount": amount,
41 "unlock_date": unlock_date,
42 "lock_ID":lock_id
43 }
44 return lock_info
45
46 @export
47 def withdraw(contract: str):
48 '''withdraw all LPs at once'''
49 user = ctx.caller
50 lock_data = lock_info[contract, user]
51 amount = lp_points[contract, user]
52 assert amount > 0, 'no LPs to unlock.'
53 #assert now >= lock_data["unlock_date"] , "cannot withdraw before unlock date."
54 #rswp = I.import_module('con_amm_v9')
55 #rswp.transfer_liquidity(contract=contract, to=user, amount=amount)
56 lp_points[contract, user] -= amount
57 lock_data["amount"] -= amount
58 lock_data["unlock_date"] = "expired"
59 return lp_points[contract, user],lock_data
60
61 @export
62 def withdraw_part(contract: str, amount: float):
63 '''withdraw part of locked LPs'''
64 assert amount > 0, "negative value not allowed!"
65 user = ctx.caller
66 lock_data = lock_info[contract, user]
67 lp_amount = lp_points[contract, user]
68 assert lp_amount > 0, 'no LPs to unlock.'
69 assert lp_amount >= amount, "not enough LPs to withdraw"
70 #assert now >= lock_data["unlock_date"] , "cannot withdraw before unlock date."
71 #rswp = I.import_module('con_amm_v9')
72 #rswp.transfer_liquidity(contract=contract, to=user, amount=amount)
73 lp_points[contract, user] -= amount
74 lock_data["amount"] -= amount
75 lock_data["unlock_date"] = "expired"
76 return lock_data
77
78
79 @export
80 def extend_lock(contract: str, lock_time: int):
81 '''extend locking period whilst your LPs remains ontouched'''
82 assert lock_time > 0, "negative value not allowed!"
83 user = ctx.caller
84 lock_data = lock_info[contract, user]
85 assert lock_data, "no locked LPs found."
86 #lock_data["unlock_date"] = now
87 lock_time = datetime.timedelta(seconds=lock_time)
88 unlock_date = lock_data["unlock_date"]
89 extended_date = unlock_date + lock_time
90 assert extended_date > unlock_date, "extension cannot be lesser than unlock date."
91 lock_data["unlock_date"] = extended_date
92 return True
93
94 @export
95 def lock_more_lp(contract: str, amount: float):
96 '''lock more LPs in addition to what is previously locked in the same lock period'''
97 assert amount > 0, "negative value not allowed!"
98 user = ctx.caller
99 lock_data = lock_info[contract, user]
100 assert lock_data, "no locked LPs found."
101 rswp = I.import_module('con_amm_v9')
102 rswp.transfer_liquidity_from(contract=contract, to=ctx.this, main_account=user, amount=amount)
103 lp_points[contract, user] += amount
104 lock_data["amount"] += amount
105 return True
106

Byte Code

e3000000000000000000000000050000004000000073a200000065005a0165026400640164028d025a03650264036400640464058d035a046406640784005a0565066400830165076508650964089c036409640a840483015a0a6506640083016507640b9c01640c640d840483015a0b65066400830165076508640e9c02640f6410840483015a0c6506640083016507650964119c0264126413840483015a0d65066400830165076508640e9c0264146415840483015a0e641653002917da0a636f6e5f6c6c5f743030da096c6f636b5f696e666f2902da08636f6e7472616374da046e616d65e900000000da096c705f706f696e74732903da0d64656661756c745f76616c756572030000007204000000630000000000000000000000000a00000043000000734000000064017400640c3c0074016a0164046405640664076408640783066401640174016a016404640964066407640864078306640a640b9c057402640d3c0064005300290e4ee964000000da0b636f6e5f7374616b656974da403238663766613365636262376437393465363233613636393266303961303661393132663538666634373861343464303334643137346464356539666163396569e5070000e909000000e90b0000007205000000e90e000000e90a000000da0f65717765776567686a6768686768662905da096c6f636b5f64617465da0e696e697469616c5f616d6f756e74da06616d6f756e74da0b756e6c6f636b5f64617465da076c6f636b5f494429027209000000720a00000029027209000000720a0000002903da0b5f5f6c705f706f696e7473da086461746574696d65da0b5f5f6c6f636b5f696e666fa90072180000007218000000da00da045f5f5f5f0600000073080000000003080312010801721a000000290372030000007212000000da096c6f636b5f74696d656303000000000000000a000000060000004300000073e40000007c0164016b04731074006402830182017c0264016b04732074006402830182017401640364046405640464068d047d037c037c001900734674007c009b0064079d028301820174026a037d0474046a057c0264088d017d0274067d057c057c0217007d067c067c056b047374740064098301820174076a08640383017d077c076a097c0074026a0a7c047c01640a8d040100740b7c007c046602050019007c01370003003c007c009b007c049b007c019b007c029b007c059b009d057d08740c6a0d7c0883017d097c057c017c017c067c09640b9c05740e7c007c0466023c00740e5300290c4e72050000007a1b6e656761746976652076616c7565206e6f7420616c6c6f77656421da0a636f6e5f616d6d5f7639da05706169727372010000002904da10666f726569676e5f636f6e7472616374da0c666f726569676e5f6e616d65720300000072040000007a232d63757272656e63792854415529207061697220646f6573206e6f74206578697374212901da077365636f6e64737a0d696e76616c69642074696d652129047203000000da02746fda0c6d61696e5f6163636f756e747212000000290572100000007211000000721200000072130000007214000000290fda0e417373657274696f6e4572726f72da0b466f726569676e48617368da03637478da0663616c6c65727216000000da0974696d6564656c7461da036e6f77da0149da0d696d706f72745f6d6f64756c65da177472616e736665725f6c69717569646974795f66726f6dda04746869737215000000da07686173686c6962da067368613235367217000000290a72030000007212000000721b000000da075f5f7061697273da0475736572da05746f6461797213000000da0472737770da096861736861626c6573da076c6f636b5f6964721800000072180000007219000000da076c6f636b5f6c7011000000732800000000021001100104010c01160106010c010401080110010a010a010a01140118010a01020106011001723500000029017203000000630100000000000000040000000400000043000000736a00000074006a017d0174027c007c01660219007d0274037c007c01660219007d037c0364016b04732e740464028301820174037c007c016602050019007c03380003003c007c026403050019007c03380003003c0064047c0264053c0074037c007c01660219007c026602530029067a18776974686472617720616c6c204c5073206174206f6e636572050000007a116e6f204c507320746f20756e6c6f636b2e7212000000da07657870697265647213000000290572250000007226000000721700000072150000007223000000290472030000007230000000da096c6f636b5f646174617212000000721800000072180000007219000000da087769746864726177290000007310000000000306010c010c0110011401100108017238000000290272030000007212000000630200000000000000050000000400000043000000737e0000007c0164016b047310740064028301820174016a027d0274037c007c02660219007d0374047c007c02660219007d047c0464016b04733e74006403830182017c047c016b05734e740064048301820174047c007c026602050019007c01380003003c007c036405050019007c01380003003c0064067c0364073c007c03530029087a1b77697468647261772070617274206f66206c6f636b6564204c507372050000007a1b6e656761746976652076616c7565206e6f7420616c6c6f776564217a116e6f204c507320746f20756e6c6f636b2e7a1a6e6f7420656e6f756768204c507320746f20776974686472617772120000007236000000721300000029057223000000722500000072260000007217000000721500000029057203000000721200000072300000007237000000da096c705f616d6f756e74721800000072180000007219000000da0d77697468647261775f706172743600000073140000000003100106010c010c0110011001140110010801723a00000029027203000000721b00000063020000000000000006000000030000004300000073660000007c0164016b047310740064028301820174016a027d0274037c007c02660219007d037c03732e740064038301820174046a057c0164048d017d017c03640519007d047c047c0117007d057c057c046b04735a74006406830182017c057c0364053c006407530029087a37657874656e64206c6f636b696e6720706572696f64207768696c737420796f7572204c50732072656d61696e73206f6e746f756368656472050000007a1b6e656761746976652076616c7565206e6f7420616c6c6f776564217a146e6f206c6f636b6564204c507320666f756e642e2901722000000072130000007a2c657874656e73696f6e2063616e6e6f74206265206c6573736572207468616e20756e6c6f636b20646174652e54290672230000007225000000722600000072170000007216000000722700000029067203000000721b000000723000000072370000007213000000da0d657874656e6465645f64617465721800000072180000007219000000da0b657874656e645f6c6f636b4500000073140000000003100106010c010c010c010801080110010801723c00000063020000000000000005000000060000004300000073740000007c0164016b047310740064028301820174016a027d0274037c007c02660219007d037c03732e740064038301820174046a05640483017d047c046a067c0074016a077c027c0164058d04010074087c007c026602050019007c01370003003c007c036406050019007c01370003003c006407530029087a4e6c6f636b206d6f7265204c507320696e206164646974696f6e20746f20776861742069732070726576696f75736c79206c6f636b656420696e207468652073616d65206c6f636b20706572696f6472050000007a1b6e656761746976652076616c7565206e6f7420616c6c6f776564217a146e6f206c6f636b6564204c507320666f756e642e721c00000029047203000000722100000072220000007212000000721200000054290972230000007225000000722600000072170000007229000000722a000000722b000000722c0000007215000000290572030000007212000000723000000072370000007232000000721800000072180000007219000000da0c6c6f636b5f6d6f72655f6c705400000073140000000003100106010c010c010a010a010a0114011001723d0000004e290fda09696d706f72746c69627229000000da044861736872170000007215000000721a000000da085f5f6578706f7274da03737472da05666c6f6174da03696e7472350000007238000000723a000000723c000000723d0000007218000000721800000072180000007219000000da083c6d6f64756c653e01000000731a00000004010c010e03080b060114170601100c0601120e0601120e0601