Contract con_distr_rewards_yeti_4


Contract Code


  
1 I = importlib
2
3 import currency as tau
4 import con_yeti_contract_7 as yeti_token
5 import con_rocketswap_official_v1_1
6
7 YETI = 'con_yeti_contract_7'
8 DEX = con_rocketswap_official_v1_1
9 REWARDS_CONTRACT = 'con_distr_rewards_yeti_4'
10
11 yeti_balance = ForeignHash(foreign_contract=YETI, foreign_name='balances')
12
13 operator = Variable()
14 tau_to_distribute = Variable()
15
16 @construct
17 def init():
18 operator.set(YETI)
19 tau_to_distribute.set(decimal('0.00'))
20 approve()
21
22
23 @export
24 def approve():
25 tau.approve(amount=9999999999999999999999, to='con_rocketswap_official_v1_1')
26 yeti_token.approve(amount=9999999999999999999999, to='con_rocketswap_official_v1_1')
27
28 @export
29 def sell_yeti_for_rewards(cost_of_distr: float, reward_token: str):
30 #check if caller is operator
31 assert_operator()
32 #get total YETI balance of this contract
33 yeti_amount = yeti_balance[REWARDS_CONTRACT]
34 #sell all YETI for TAU
35 DEX.sell(contract=YETI, token_amount=yeti_amount)
36 #get total TAU balance of this contract
37 currency_balance = ForeignHash(foreign_contract='currency', foreign_name='balances')
38 currency_amount = currency_balance[REWARDS_CONTRACT]
39
40 assert currency_amount > cost_of_distr, 'Not enough to cover distribution fees'
41 #amount worth distributing
42 currency_amount -= cost_of_distr
43
44 if reward_token == 'currency':
45 tau_to_distribute.set(tau_to_distribute.get() + currency_amount)
46 else:
47 DEX.buy(contract=reward_token, currency_amount=currency_amount)
48
49 @export
50 def distribute_rewards(reward_token: str, addresses: list, amounts: list):
51 assert_operator()
52 for num in range(len(addresses)):
53 address = addresses[num]
54 amount = amounts[num]
55
56 if reward_token == 'currency':
57 if not address.startswith('con_'):
58 assert tau_to_distribute.get() >= decimal('0'), 'TAU for distribution is exhausted!'
59 tau.transfer(amount=amount, to=address)
60 tau_to_distribute.set(tau_to_distribute.get() - amount)
61 else:
62 token = I.import_module(reward_token)
63 if not address.startswith('con_'):
64 token.transfer(amount=amount, to=address)
65
66 def assert_operator():
67 assert ctx.caller == operator.get(), 'Only operator can call!'
68

Byte Code

e3000000000000000000000000060000004000000073a600000065005a01640064016c025a03640064016c045a05640064016c065a0664025a0765065a0864035a09650a650764046403640564068d045a0b650c6403640764088d025a0d650c6403640964088d025a0e640a640b84005a0f651064038301640c640d840083015a1165106403830165126513640e9c02640f6410840483015a1465106403830165136515651564119c0364126413840483015a166414641584005a17640153002916e9000000004eda13636f6e5f796574695f636f6e74726163745f37da18636f6e5f64697374725f726577617264735f796574695f34da0862616c616e636573da0c796574695f62616c616e63652904da10666f726569676e5f636f6e7472616374da0c666f726569676e5f6e616d65da08636f6e7472616374da046e616d65da086f70657261746f72290272080000007209000000da117461755f746f5f64697374726962757465630000000000000000000000000300000043000000732200000074006a0174028301010074036a01740464018301830101007405830001006400530029024e7a04302e30302906da0a5f5f6f70657261746f72da03736574da0459455449da135f5f7461755f746f5f64697374726962757465da07646563696d616cda07617070726f7665a90072120000007212000000da00da045f5f5f5f0f000000730600000000010a010e017214000000630000000000000000000000000400000043000000732000000074006a016401640264038d02010074026a016401640264038d0201006400530029044e6c05000000ff7f7f64ea26064fe121da1c636f6e5f726f636b6574737761705f6f6666696369616c5f76315f312902da06616d6f756e74da02746f2903da037461757211000000da0a796574695f746f6b656e72120000007212000000721200000072130000007211000000150000007308000000000206010801060172110000002902da0d636f73745f6f665f6469737472da0c7265776172645f746f6b656e630200000000000000050000000600000043000000737a0000007400830001007401740219007d0274036a0474057c0264018d0201007406640264036404640564068d047d037c03740219007d047c047c006b04734474076407830182017c047c0038007d047c0164026b02726874086a0974086a0a83007c041700830101006e0e74036a0b7c017c0464088d0201006400530029094e29027208000000da0c746f6b656e5f616d6f756e74da0863757272656e637972040000007203000000da1063757272656e63795f62616c616e6365290472060000007207000000720800000072090000007a254e6f7420656e6f75676820746f20636f76657220646973747269627574696f6e206665657329027208000000da0f63757272656e63795f616d6f756e74290cda115f5f6173736572745f6f70657261746f72da0e5f5f796574695f62616c616e6365da10524557415244535f434f4e5452414354da03444558da0473656c6c720e000000da0b466f726569676e48617368da0e417373657274696f6e4572726f72720f000000720d000000da03676574da036275792905721a000000721b000000da0b796574695f616d6f756e74da125f5f63757272656e63795f62616c616e6365721f000000721200000072120000007213000000da1573656c6c5f796574695f666f725f726577617264731d00000073180000000002060108010e0104010401080108011001080108011402722b0000002903721b000000da09616464726573736573da07616d6f756e7473630300000000000000070000000500000043000000739e0000007400830001007892740174027c018301830144005d827d037c017c0319007d047c027c0319007d057c0064016b0272747c046a0364028301739674046a0583007406640383016b057352740764048301820174086a097c057c0464058d02010074046a0a74046a0583007c051800830101007114740b6a0c7c0083017d067c046a036402830173147c066a097c057c0464058d020100711457006400530029064e721d000000da04636f6e5fda01307a2254415520666f7220646973747269627574696f6e2069732065786861757374656421290272160000007217000000290d7220000000da0572616e6765da036c656eda0a73746172747377697468720f0000007227000000721000000072260000007218000000da087472616e73666572720d000000da0149da0d696d706f72745f6d6f64756c652907721b000000722c000000722d000000da036e756dda07616464726573737216000000da05746f6b656e721200000072120000007213000000da12646973747269627574655f726577617264732e000000731a0000000002060112010801080108010a01120106010e0114020a010a017239000000630000000000000000000000000200000043000000731a00000074006a0174026a0383006b02731674046401830182016400530029024e7a174f6e6c79206f70657261746f722063616e2063616c6c212905da03637478da0663616c6c6572720c0000007227000000722600000072120000007212000000721200000072130000007220000000400000007302000000000172200000002918da09696d706f72746c69627234000000721d0000007218000000720200000072190000007215000000720e0000007223000000722200000072250000007221000000da085661726961626c65720c000000720f0000007214000000da085f5f6578706f72747211000000da05666c6f6174da03737472722b000000da046c697374723900000072200000007212000000721200000072120000007213000000da083c6d6f64756c653e010000007324000000040108010801080104010401040106010a010c0104010803080610080601121006011411