Contract currency_2

Created On NaN secs ago - Invalid Date UTC+0

Contract Code

1 import currency
2 balances = Hash(default_value=0, contract='currency_2', name='balances')
3 tau_ratio = Variable(contract='currency_2', name='tau_ratio')
4 total_supply = Variable(contract='currency_2', name='total_supply')
5 tau_refund_amount = Variable(contract='currency_2', name='tau_refund_amount')
6 operator = Variable(contract='currency_2', name='operator')
7
8
9 def ():
10 balances[ctx.signer] = 100
11 operator.set(ctx.signer)
12 total_supply.set(100)
13 tau_refund_amount.set(0)
14 tau_ratio.set(1)
15
16
17 @export('currency_2')
18 def transfer(amount: float, to: str):
19 assert amount > 0, 'Cannot send negative balances!'
20 amount = amount / tau_ratio.get()
21 sender = ctx.caller
22 if ctx.signer == ctx.caller and tau_refund_amount.get() > 0:
23 currency.transfer(tau_refund_amount.get(), ctx.caller)
24 assert balances[sender] >= amount, 'Not enough coins to send!'
25 balances[sender] -= amount
26 balances[to] += amount
27
28
29 @export('currency_2')
30 def balance_of(account: str):
31 return balances[account] * tau_ratio.get()
32
33
34 @export('currency_2')
35 def allowance(owner: str, spender: str):
36 return balances[owner, spender] * tau_ratio.get()
37
38
39 @export('currency_2')
40 def approve(amount: float, to: str):
41 assert amount > 0, 'Cannot send negative balances!'
42 amount = amount / tau_ratio.get()
43 sender = ctx.caller
44 balances[sender, to] += amount
45 return balances[sender, to] * tau_ratio.get()
46
47
48 @export('currency_2')
49 def transfer_from(amount: float, to: str, main_account: str):
50 assert amount > 0, 'Cannot send negative balances!'
51 amount = amount / tau_ratio.get()
52 sender = ctx.caller
53 assert balances[main_account, sender
54 ] >= amount, 'Not enough coins approved to send! You have {} and are trying to spend {}'.format(
55 balances[main_account, sender], amount)
56 assert balances[main_account] >= amount, 'Not enough coins to send!'
57 balances[main_account, sender] -= amount
58 balances[main_account] -= amount
59 balances[to] += amount
60
61
62 @export('currency_2')
63 def determine_ratio():
64 ratio = currency.balance_of(ctx.this) / total_supply.get()
65 tau_ratio.set(ratio)
66 return ratio
67
68
69 @export('currency_2')
70 def legacy_transfer(amount: float, to: str):
71 assert amount > 0, 'Cannot send negative balances!'
72 total = total_supply.get()
73 ratio = currency.balance_of(ctx.this) / total
74 amount2 = amount / ratio
75 sender = ctx.caller
76 assert balances[sender] >= amount2, 'Not enough coins to send!'
77 balances[sender] -= amount2
78 tau_ratio.set(ratio)
79 total_supply.set(total - amount2)
80 currency.transfer(amount, to)
81
82
83 @export('currency_2')
84 def redeem(amount: float):
85 legacy_transfer(amount, ctx.caller)
86
87
88 @export('currency_2')
89 def mint(amount_in_tau: float):
90 assert amount_in_tau > 0, 'Cannot mint negative balances!'
91 sender = ctx.caller
92 ratio = currency.balance_of(ctx.this) / total_supply.get()
93 tau_ratio.set(ratio)
94 currency.transfer_from(amount_in_tau, ctx.this, ctx.caller)
95 amount = amount_in_tau / ratio
96 balances[sender] += amount
97 total_supply.set(total_supply.get() + amount)
98
99
100 @export('currency_2')
101 def set_cashback_amount(amount: float):
102 assert amount < 1, 'Too much!'
103 assert ctx.caller == operator.get()
104 tau_refund_amount.set(amount)
105