Contract con_gold_ape_003


Contract Code


  
1 import currency as tau
2 import con_gold_contract as gold
3
4 owner = Variable()
5 tau_amount = Variable()
6 data = Hash(default_value=0)
7 reserve = Variable()
8 burn = Variable()
9
10 @construct
11 def init():
12 owner.set(ctx.caller)
13 tau_amount.set(1500)
14 reserve.set("96dae3b6213fb80eac7c6f4fa0fd26f34022741c56773107b20199cb43f5ed62")
15 burn.set("0000000000000BURN0000000000000")
16
17 @export
18 def subscribe():
19 gold_price = ForeignHash(foreign_contract='con_rocketswap_official_v1_1', foreign_name='prices')
20 gold_amount = tau_amount.get() / gold_price["con_gold_contract"]
21
22 gold.transfer_from(amount=gold_amount, to=ctx.this, main_account=ctx.caller)
23
24 data[ctx.caller] += gold_amount
25 data[ctx.caller, "start"] = now
26
27 @export
28 def unsubscribe():
29
30
31 time_delta = now - data[ctx.caller, "start"]
32
33 if time_delta <= datetime.timedelta(days=30):
34 payout = data[ctx.caller] / 100 * 30
35 elif time_delta <= datetime.timedelta(days=90):
36 payout = data[ctx.caller] / 100 * 50
37 elif time_delta <= datetime.timedelta(days=120):
38 payout = data[ctx.caller] / 100 * 70
39 else:
40 payout = data[ctx.caller] / 100 * 80
41
42 # Pay back user
43 gold.transfer(amount=payout, to=ctx.caller)
44
45 amount_delta = data[ctx.caller] - payout
46
47 # Burn half or remaining amount
48 gold.transfer(amount=int(amount_delta / 2), to=burn.get())
49
50 # Send other half to reserve
51 gold.transfer(amount=int(amount_delta - (amount_delta / 2)), to=reserve.get())
52
53 data[ctx.caller] = 0
54
55 return payout
56
57 @export
58 def set_tau_amount(amount: int):
59 assert ctx.caller == owner.get(), "Only owner can adjust TAU amount"
60 assert amount >= 0, "Amount of TAU can't be negative"
61
62 tau_amount.set(amount)
63
64 @export
65 def deposit_gold(amount: float):
66 gold.transfer_from(amount=amount, to=ctx.this, main_account=ctx.caller)
67
68 @export
69 def withdraw_gold(amount: float):
70 assert owner.get() == ctx.caller, "Only the owner can withdraw GOLD"
71
72 gold.transfer(amount=amount, to=ctx.caller)
73

Byte Code

e3000000000000000000000000050000004000000073bc000000640064016c005a01640064016c025a0365046402640364048d025a0565046402640564048d025a06650764006402640664078d035a0865046402640864048d025a0965046402640964048d025a0a640a640b84005a0b650c64028301640c640d840083015a0d650c64028301640e640f840083015a0e650c64028301650f64109c0164116412840483015a10650c64028301651164109c0164136414840483015a12650c64028301651164109c0164156416840483015a13640153002917e9000000004eda10636f6e5f676f6c645f6170655f303033da056f776e65722902da08636f6e7472616374da046e616d65da0a7461755f616d6f756e74da04646174612903da0d64656661756c745f76616c756572040000007205000000da0772657365727665da046275726e630000000000000000000000000200000043000000732e00000074006a0174026a038301010074046a0164018301010074056a0164028301010074066a016403830101006400530029044e69dc050000da4039366461653362363231336662383065616337633666346661306664323666333430323237343163353637373331303762323031393963623433663565643632da1e303030303030303030303030304255524e303030303030303030303030302907da075f5f6f776e6572da03736574da03637478da0663616c6c6572da0c5f5f7461755f616d6f756e74da095f5f72657365727665da065f5f6275726ea90072140000007214000000da00da045f5f5f5f0a000000730a00000000010c010a0104010601721600000063000000000000000002000000060000004300000073580000007400640164026403640464058d047d0074016a0283007c00640619001b007d0174036a047c0174056a0674056a0764078d030100740874056a07050019007c01370003003c007409740874056a07640866023c006400530029094eda1c636f6e5f726f636b6574737761705f6f6666696369616c5f76315f31da067072696365737202000000da0a676f6c645f70726963652904da10666f726569676e5f636f6e7472616374da0c666f726569676e5f6e616d6572040000007205000000da11636f6e5f676f6c645f636f6e74726163742903da06616d6f756e74da02746fda0c6d61696e5f6163636f756e74da057374617274290ada0b466f726569676e486173687211000000da03676574da04676f6c64da0d7472616e736665725f66726f6d720f000000da04746869737210000000da065f5f64617461da036e6f772902da0c5f5f676f6c645f7072696365da0b676f6c645f616d6f756e74721400000072140000007215000000da0973756273637269626512000000730e0000000002020104010a01100114021201722a00000063000000000000000003000000050000004300000073f40000007400740174026a0364016602190018007d007c0074046a05640264038d016b017236740174026a03190064041b00640214007d016e5a7c0074046a05640564038d016b01725a740174026a03190064041b00640614007d016e367c0074046a05640764038d016b01727e740174026a03190064041b00640814007d016e12740174026a03190064041b00640914007d0174066a077c0174026a03640a8d020100740174026a0319007c0118007d0274066a0774087c02640b1b00830174096a0a8300640a8d02010074066a0774087c027c02640b1b0018008301740b6a0a8300640a8d020100640c740174026a033c007c015300290d4e7220000000e91e0000002901da0464617973e964000000e95a000000e932000000e978000000e946000000e9500000002902721d000000721e000000e9020000007201000000290c72270000007226000000720f0000007210000000da086461746574696d65da0974696d6564656c74617223000000da087472616e73666572da03696e747213000000722200000072120000002903da0a74696d655f64656c7461da067061796f7574da0c616d6f756e745f64656c7461721400000072140000007215000000da0b756e7375627363726962651e000000731c00000000021201100114011001140110011402120110010e011a011e020a01723b0000002901721d000000630100000000000000010000000200000043000000733400000074006a0174026a0383006b02731674046401830182017c0064026b057326740464038301820174056a067c00830101006400530029044e7a204f6e6c79206f776e65722063616e2061646a7573742054415520616d6f756e7472010000007a1f416d6f756e74206f66205441552063616e2774206265206e656761746976652907720f0000007210000000720d0000007222000000da0e417373657274696f6e4572726f727211000000720e0000002901721d000000721400000072140000007215000000da0e7365745f7461755f616d6f756e74320000007306000000000216011001723d000000630100000000000000010000000500000043000000731800000074006a017c0074026a0374026a0464018d0301006400530029024e2903721d000000721e000000721f000000290572230000007224000000720f000000722500000072100000002901721d000000721400000072140000007215000000da0c6465706f7369745f676f6c643900000073020000000002723e000000630100000000000000010000000400000043000000732a00000074006a01830074026a036b027316740464018301820174056a067c0074026a0364028d0201006400530029034e7a204f6e6c7920746865206f776e65722063616e20776974686472617720474f4c442902721d000000721e0000002907720d0000007222000000720f0000007210000000723c000000722300000072360000002901721d000000721400000072140000007215000000da0d77697468647261775f676f6c643e000000730400000000021601723f0000002914da0863757272656e6379da03746175721c0000007223000000da085661726961626c65720d0000007211000000da04486173687226000000721200000072130000007216000000da085f5f6578706f7274722a000000723b0000007237000000723d000000da05666c6f6174723e000000723f0000007214000000721400000072140000007215000000da083c6d6f64756c653e01000000731e000000080108010c010c010e010c010c030808100c101406011006060110040601