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