Contract con_limerence_lst001_lst002


Contract Code


  
1 I = importlib
2
3 rswp_reserves = ForeignHash(foreign_contract='con_rocketswap_official_v1_1', foreign_name='reserves')
4 rswp_state = ForeignHash(foreign_contract='con_rocketswap_official_v1_1', foreign_name='state')
5
6
7 balances = Hash(default_value=0)
8 metadata = Hash()
9 last_predicted_price = Variable()
10 owner = Variable()
11
12 @construct
13 def init():
14 # Token info
15 metadata["token_name"] = 'LIM'
16 metadata["token_symbol"] = 'LIM'
17 metadata["token_contract"] = 'con_limerence_lst001_lst002'
18 balances[ctx.caller] = 1_000_000
19 owner.set(ctx.caller)
20 last_predicted_price.set(0)
21 # DEX
22 metadata["dex"] = ["con_rocketswap_official_v1_1"]
23 metadata["minimum_price"] = 1
24
25
26
27 @export
28 def change_metadata(key: str, value: Any):
29 assert_owner()
30 metadata[key] = value
31
32 @export
33 def transfer(amount: float, to: str):
34 assert amount > 0, "Cannot send negative balances!"
35
36 sender = ctx.caller
37
38 assert balances[sender] >= amount, "Not enough CURRENCY to send!"
39
40 balances[sender] -= amount
41 balances[to] += amount
42
43 @export
44 def approve(amount: float, to: str):
45 assert amount > 0, "Cannot send negative balances!"
46
47 sender = ctx.caller
48 balances[sender, to] += amount
49 return balances[sender, to]
50
51 @export
52 def transfer_from(amount: float, to: str, main_account: str):
53 assert amount > 0, "Cannot send negative balances!"
54 sender = ctx.caller
55
56 assert balances[main_account, sender] >= amount, f"Not enough coins approved to send! You have {balances[main_account, sender]} and are trying to spend {amount}"
57 assert balances[main_account] >= amount, "Not enough coins to send!"
58
59
60 if to in metadata["dex"]:
61
62 # check if there is a rocketswap market for this token
63 if rswp_reserves[metadata["token_contract"]] is None: # reserve initial value is None when testing locally
64 balances[main_account, sender] -= amount
65 balances[main_account] -= amount
66
67 balances[to] += amount
68 return
69
70
71 if rswp_reserves[metadata["token_contract"]] is [0,0]:
72 balances[main_account, sender] -= amount
73 balances[main_account] -= amount
74
75 balances[to] += amount
76 return
77
78 # predict new price if there should be a sell
79 currency_reserve, token_reserve = rswp_reserves[metadata["token_contract"]]
80 k = currency_reserve * token_reserve
81 new_token_reserve = token_reserve + amount
82 new_currency_reserve = k / new_token_reserve
83 currency_purchased = currency_reserve - new_currency_reserve
84 fee = currency_purchased * rswp_state["FEE_PERCENTAGE"] * 1
85 currency_purchased -= fee
86 new_currency_reserve += fee
87
88 if currency_purchased > 0:
89 price = new_currency_reserve / new_token_reserve
90
91 last_predicted_price.set(price)
92
93 assert price > metadata["minimum_price"], f"selling not possible at token price: ~{last_predicted_price.get()}"
94
95 balances[main_account, sender] -= amount
96 balances[main_account] -= amount
97
98 balances[to] += amount
99
100 return
101
102 balances[main_account, sender] -= amount
103 balances[main_account] -= amount
104
105 balances[to] += amount
106
107 def assert_owner():
108 assert ctx.caller is owner.get(), "Only owner can call this method!"
109
110
111

Byte Code

e3000000000000000000000000060000004000000073cc00000065005a016502640064016402640364048d045a036502640064056402640664048d045a04650564076402640864098d035a0665056402640a640b8d025a0765086402640c640b8d025a0965086402640d640b8d025a0a640e640f84005a0b650c64028301650d650e64109c0264116412840483015a0f650c640283016510650d64139c0264146415840483015a11650c640283016510650d64139c0264166417840483015a12650c640283016510650d650d64189c036419641a840483015a13641b641c84005a14641d5300291eda1c636f6e5f726f636b6574737761705f6f6666696369616c5f76315f31da087265736572766573da1b636f6e5f6c696d6572656e63655f6c73743030315f6c7374303032da0d727377705f72657365727665732904da10666f726569676e5f636f6e7472616374da0c666f726569676e5f6e616d65da08636f6e7472616374da046e616d65da057374617465da0a727377705f7374617465e900000000da0862616c616e6365732903da0d64656661756c745f76616c756572070000007208000000da086d65746164617461290272070000007208000000da146c6173745f7072656469637465645f7072696365da056f776e6572630000000000000000000000000300000043000000734e0000006401740064023c006401740064033c006404740064053c006406740174026a033c0074046a0574026a038301010074066a0564078301010064086701740064093c00640a7400640b3c0064005300290c4eda034c494dda0a746f6b656e5f6e616d65da0c746f6b656e5f73796d626f6c7203000000da0e746f6b656e5f636f6e74726163746940420f00720b0000007201000000da03646578e901000000da0d6d696e696d756d5f70726963652907da0a5f5f6d65746164617461da0a5f5f62616c616e636573da03637478da0663616c6c6572da075f5f6f776e6572da03736574da165f5f6c6173745f7072656469637465645f7072696365a900721f000000721f000000da00da045f5f5f5f10000000731000000000010801080108010a010c010a010a0172210000002902da036b6579da0576616c756563020000000000000002000000030000004300000073120000007400830001007c0174017c003c006400530029014e2902da0e5f5f6173736572745f6f776e65727218000000290272220000007223000000721f000000721f0000007220000000da0f6368616e67655f6d657461646174611b00000073040000000002060172250000002902da06616d6f756e74da02746f630200000000000000030000000400000043000000734e0000007c0064016b047310740064028301820174016a027d0274037c0219007c006b05732a740064038301820174037c02050019007c00380003003c0074037c01050019007c00370003003c006400530029044e720b0000007a1e43616e6e6f742073656e64206e656761746976652062616c616e636573217a1c4e6f7420656e6f7567682043555252454e435920746f2073656e64212904da0e417373657274696f6e4572726f72721a000000721b0000007219000000290372260000007227000000da0673656e646572721f000000721f0000007220000000da087472616e7366657221000000730a00000000021001060114011001722a00000063020000000000000003000000040000004300000073360000007c0064016b047310740064028301820174016a027d0274037c027c016602050019007c00370003003c0074037c027c0166021900530029034e720b0000007a1e43616e6e6f742073656e64206e656761746976652062616c616e6365732129047228000000721a000000721b00000072190000002903722600000072270000007229000000721f000000721f0000007220000000da07617070726f76652a00000073080000000002100106011401722b000000290372260000007227000000da0c6d61696e5f6163636f756e746303000000000000000c000000050000004300000073f40100007c0064016b047310740064028301820174016a027d0374037c027c03660219007c006b0573427400640374037c027c03660219009b0064047c009b009d048301820174037c0219007c006b05735674006405830182017c017404640619006b06900172bc7405740464071900190064006b0872ac74037c027c036602050019007c00380003003c0074037c02050019007c00380003003c0074037c01050019007c00370003003c0064005300740574046407190019006401640167026b0872f874037c027c036602050019007c00380003003c0074037c02050019007c00380003003c0074037c01050019007c00370003003c0064005300740574046407190019005c027d047d057c047c0514007d067c057c0017007d077c067c071b007d087c047c0818007d097c097406640819001400640914007d0a7c097c0a38007d097c087c0a37007d087c0964016b04900172b87c087c071b007d0b74076a087c0b830101007c0b7404640a19006b04900173847400640b74076a0983009b009d028301820174037c027c036602050019007c00380003003c0074037c02050019007c00380003003c0074037c01050019007c00370003003c006400530074037c027c036602050019007c00380003003c0074037c02050019007c00380003003c0074037c01050019007c00370003003c0064005300290c4e720b0000007a1e43616e6e6f742073656e64206e656761746976652062616c616e636573217a2c4e6f7420656e6f75676820636f696e7320617070726f76656420746f2073656e642120596f752068617665207a1920616e642061726520747279696e6720746f207370656e64207a194e6f7420656e6f75676820636f696e7320746f2073656e642172150000007214000000da0e4645455f50455243454e54414745721600000072170000007a2673656c6c696e67206e6f7420706f737369626c6520617420746f6b656e2070726963653a207e290a7228000000721a000000721b00000072190000007218000000da0f5f5f727377705f7265736572766573da0c5f5f727377705f7374617465721e000000721d000000da03676574290c72260000007227000000722c0000007229000000da1063757272656e63795f72657365727665da0d746f6b656e5f72657365727665da016bda116e65775f746f6b656e5f72657365727665da146e65775f63757272656e63795f72657365727665da1263757272656e63795f707572636861736564da03666565da057072696365721f000000721f0000007220000000da0d7472616e736665725f66726f6d32000000734a0000000002100106010a01220114010e01100114011001100104011401140110011001040104010c0108010801080108011001080108010a0108010a01100110011401100110010401140110017239000000630000000000000000000000000200000043000000731a00000074006a0174026a0383006b08731674046401830182016400530029024e7a204f6e6c79206f776e65722063616e2063616c6c2074686973206d6574686f64212905721a000000721b000000721c00000072300000007228000000721f000000721f000000721f000000722000000072240000005b0000007302000000000172240000004e2915da09696d706f72746c6962da0149da0b466f726569676e48617368722e000000722f000000da044861736872190000007218000000da085661726961626c65721e000000721c0000007221000000da085f5f6578706f7274da03737472da03416e797225000000da05666c6f6174722a000000722b00000072390000007224000000721f000000721f000000721f0000007220000000da083c6d6f64756c653e01000000732c0000000401020104010a01040104010801060108010c01040108010c03080b06011205060112080601120706011428