Mirror Chain

A New Playground For Degens 🪞

MIR-20

Token Standard
GitHub Repo

MIR-20 is a simple ERC20-like standard designed for the Mirror Chain. It is a minimal and clean token implementation in Python.

Total Supply
1,000,000,000
Ownership
No owner
Allowance
None
Supply Rules
No mint
MIR-20
1
class MIR20:
2
DECIMALS = 6
3
TOTAL_UNITS = 1_000_000_000 * (10 ** DECIMALS)
4
5
def __init__(self, deployer):
6
self.name = "MIR-20"
7
self.symbol = "MIR"
8
self.decimals = self.DECIMALS
9
10
# fixed supply
11
self._total_supply = self.TOTAL_UNITS
12
13
# assign entire supply to deployer
14
self._balances = {deployer: self.TOTAL_UNITS}
15
16
# ---------- Views ----------
17
def totalSupply(self):
18
return self._total_supply # in smallest units
19
20
def balanceOf(self, account):
21
return self._balances.get(account, 0)
22
23
# ---------- Internal helpers ----------
24
def _require(self, cond, msg):
25
if not cond:
26
raise Exception(msg)
27
28
def _add_balance(self, who, amount):
29
self._balances[who] = self._balances.get(who, 0) + amount
30
31
def _sub_balance(self, who, amount):
32
bal = self.balanceOf(who)
33
self._require(bal >= amount, "Insufficient balance")
34
self._balances[who] = bal - amount
35
if self._balances[who] == 0:
36
# optional cleanup
37
self._balances.pop(who, None)
38
39
# ---------- Actions ----------
40
def transfer(self, sender, recipient, amount_units):
41
amount_units = int(amount_units)
42
self._require(amount_units > 0, "Amount must be > 0")
43
self._require(sender != recipient, "Sender == recipient")
44
self._require(recipient is not None, "Recipient required")
45
46
self._sub_balance(sender, amount_units)
47
self._add_balance(recipient, amount_units)
48
return True
49
50
def transferMany(self, sender, pairs):
51
total = sum(int(a) for _, a in pairs)
52
self._require(total > 0, "Total must be > 0")
53
self._sub_balance(sender, total)
54
for rcpt, amt in pairs:
55
self._add_balance(rcpt, int(amt))
56
return True
57
58
# ---------- Conversion helpers ----------
59
@staticmethod
60
def to_units(amount_token):
61
return int(round(float(amount_token) * (10 ** MIR20.DECIMALS)))
62
63
@staticmethod
64
def to_token(amount_units):
65
return amount_units / float(10 ** MIR20.DECIMALS)