Contract con_distr_rewards_yeti_6


Contract Code


  
1 I = importlib
2
3 import currency as tau
4 import con_yeti_contract_11 as yeti_token
5 import con_rocketswap_official_v1_1
6
7 YETI = "con_yeti_contract_11"
8 DEX = con_rocketswap_official_v1_1
9 REWARDS_CONTRACT = "con_distr_rewards_yeti_6"
10
11
12 operator = Variable()
13 tau_to_distribute = Variable()
14
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
29 @export
30 def sell_yeti_for_rewards(cost_of_distr: float, reward_token: str):
31 # check if caller is operator
32 assert_operator()
33 # get total YETI balance of this contract
34 yeti_balance = ForeignHash(foreign_contract=YETI, foreign_name="balances")
35 yeti_amount = yeti_balance[REWARDS_CONTRACT]
36 # sell all YETI for TAU
37 DEX.sell(contract=YETI, token_amount=yeti_amount)
38 # get total TAU balance of this contract
39 currency_balance = ForeignHash(foreign_contract="currency", foreign_name="balances")
40 currency_amount = currency_balance[REWARDS_CONTRACT]
41
42 assert currency_amount > cost_of_distr, "Not enough to cover distribution fees"
43 # amount worth distributing
44 currency_amount -= cost_of_distr
45 # pay owner wallet to cover distribution fees
46 tau.transfer(amount=cost_of_distr, to=ctx.signer)
47
48 if reward_token == "currency":
49 tau_to_distribute.set(tau_to_distribute.get() + currency_amount)
50 else:
51 DEX.buy(contract=reward_token, currency_amount=currency_amount)
52
53
54 @export
55 def distribute_rewards(reward_token: str, addresses: list, amounts: list):
56 assert_operator()
57
58 if reward_token == "currency":
59 for num in range(len(addresses)):
60 address = addresses[num]
61 amount = amounts[num]
62 # contracts do not get rewards
63 if not address.startswith("con_"):
64 assert tau_to_distribute.get() >= decimal("0"
65 ), "TAU for distribution is exhausted!"
66 tau.transfer(amount=amount, to=address)
67 tau_to_distribute.set(tau_to_distribute.get() - amount)
68 else:
69 for num in range(len(addresses)):
70 address = addresses[num]
71 amount = amounts[num]
72 token = I.import_module(reward_token)
73 # contracts do not get rewards
74 if not address.startswith("con_"):
75 token.transfer(amount=amount, to=address)
76
77
78 def assert_operator():
79 assert ctx.caller == operator.get(), "Only operator can call!"
80

Byte Code

e30000000000000000000000000500000040000000739600000065005a01640064016c025a03640064016c045a05640064016c065a0664025a0765065a0864035a09650a6403640464058d025a0b650a6403640664058d025a0c6407640884005a0d650e640383016409640a840083015a0f650e6403830165106511640b9c02640c640d840483015a12650e64038301651165136513640e9c03640f6410840483015a146411641284005a15640153002913e9000000004eda14636f6e5f796574695f636f6e74726163745f3131da18636f6e5f64697374725f726577617264735f796574695f36da086f70657261746f722902da08636f6e7472616374da046e616d65da117461755f746f5f64697374726962757465630000000000000000000000000300000043000000732200000074006a0174028301010074036a01740464018301830101007405830001006400530029024e7a04302e30302906da0a5f5f6f70657261746f72da03736574da0459455449da135f5f7461755f746f5f64697374726962757465da07646563696d616cda07617070726f7665a900720e000000720e000000da00da045f5f5f5f0d000000730600000000010a010e017210000000630000000000000000000000000400000043000000732000000074006a016401640264038d02010074026a016401640264038d0201006400530029044e6c05000000ff7f7f64ea26064fe121da1c636f6e5f726f636b6574737761705f6f6666696369616c5f76315f312902da06616d6f756e74da02746f2903da03746175720d000000da0a796574695f746f6b656e720e000000720e000000720e000000720f000000720d0000001300000073080000000002060108010601720d0000002902da0d636f73745f6f665f6469737472da0c7265776172645f746f6b656e630200000000000000060000000600000043000000739a0000007400830001007401740264016402640364048d047d027c02740319007d0374046a0574027c0364058d0201007401640664016402640764048d047d047c04740319007d057c057c006b04735474066408830182017c057c0038007d0574076a087c0074096a0a64098d0201007c0164066b027288740b6a0c740b6a0d83007c051700830101006e0e74046a0e7c017c05640a8d02010064005300290b4eda0862616c616e6365737203000000da0c796574695f62616c616e63652904da10666f726569676e5f636f6e7472616374da0c666f726569676e5f6e616d657205000000720600000029027205000000da0c746f6b656e5f616d6f756e74da0863757272656e6379da1063757272656e63795f62616c616e63657a254e6f7420656e6f75676820746f20636f76657220646973747269627574696f6e206665657329027212000000721300000029027205000000da0f63757272656e63795f616d6f756e74290fda115f5f6173736572745f6f70657261746f72da0b466f726569676e48617368720a000000da10524557415244535f434f4e5452414354da03444558da0473656c6cda0e417373657274696f6e4572726f727214000000da087472616e73666572da03637478da067369676e6572720b0000007209000000da03676574da03627579290672160000007217000000da0e5f5f796574695f62616c616e6365da0b796574695f616d6f756e74da125f5f63757272656e63795f62616c616e6365721f000000720e000000720e000000720f000000da1573656c6c5f796574695f666f725f726577617264731b000000731e0000000002060104010c0108010e01040104010801080110010801100108011402722e00000029037217000000da09616464726573736573da07616d6f756e747363030000000000000007000000050000004300000073c40000007400830001007c0064016b02727878b0740174027c018301830144005d567d037c017c0319007d047c027c0319007d057c046a0364028301731c74046a0583007406640383016b057352740764048301820174086a097c057c0464058d02010074046a0a74046a0583007c05180083010100711c57006e487846740174027c018301830144005d367d037c017c0319007d047c027c0319007d05740b6a0c7c0083017d067c046a036402830173867c066a097c057c0464058d020100718657006400530029064e721d000000da04636f6e5fda01307a2254415520666f7220646973747269627574696f6e2069732065786861757374656421290272120000007213000000290d7220000000da0572616e6765da036c656eda0a73746172747377697468720b0000007229000000720c0000007225000000721400000072260000007209000000da0149da0d696d706f72745f6d6f64756c6529077217000000722f0000007230000000da036e756dda07616464726573737212000000da05746f6b656e720e000000720e000000720f000000da12646973747269627574655f726577617264732f00000073200000000002060108011201080108010a01120106010e0118021201080108010a010a01723b000000630000000000000000000000000200000043000000731a00000074006a0174026a0383006b02731674046401830182016400530029024e7a174f6e6c79206f70657261746f722063616e2063616c6c2129057227000000da0663616c6c6572720800000072290000007225000000720e000000720e000000720e000000720f0000007220000000440000007302000000000172200000002916da09696d706f72746c69627236000000721d0000007214000000720200000072150000007211000000720a00000072230000007222000000da085661726961626c657208000000720b0000007210000000da085f5f6578706f7274720d000000da05666c6f6174da03737472722e000000da046c697374723b0000007220000000720e000000720e000000720e000000720f000000da083c6d6f64756c653e01000000732000000004010801080108010401040104010c0104010803080610080601121306011414