MIR-20
Token StandardMIR-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
1class MIR20:2DECIMALS = 63TOTAL_UNITS = 1_000_000_000 * (10 ** DECIMALS)45def __init__(self, deployer):6self.name = "MIR-20"7self.symbol = "MIR"8self.decimals = self.DECIMALS910# fixed supply11self._total_supply = self.TOTAL_UNITS1213# assign entire supply to deployer14self._balances = {deployer: self.TOTAL_UNITS}1516# ---------- Views ----------17def totalSupply(self):18return self._total_supply # in smallest units1920def balanceOf(self, account):21return self._balances.get(account, 0)2223# ---------- Internal helpers ----------24def _require(self, cond, msg):25if not cond:26raise Exception(msg)2728def _add_balance(self, who, amount):29self._balances[who] = self._balances.get(who, 0) + amount3031def _sub_balance(self, who, amount):32bal = self.balanceOf(who)33self._require(bal >= amount, "Insufficient balance")34self._balances[who] = bal - amount35if self._balances[who] == 0:36# optional cleanup37self._balances.pop(who, None)3839# ---------- Actions ----------40def transfer(self, sender, recipient, amount_units):41amount_units = int(amount_units)42self._require(amount_units > 0, "Amount must be > 0")43self._require(sender != recipient, "Sender == recipient")44self._require(recipient is not None, "Recipient required")4546self._sub_balance(sender, amount_units)47self._add_balance(recipient, amount_units)48return True4950def transferMany(self, sender, pairs):51total = sum(int(a) for _, a in pairs)52self._require(total > 0, "Total must be > 0")53self._sub_balance(sender, total)54for rcpt, amt in pairs:55self._add_balance(rcpt, int(amt))56return True5758# ---------- Conversion helpers ----------59@staticmethod60def to_units(amount_token):61return int(round(float(amount_token) * (10 ** MIR20.DECIMALS)))6263@staticmethod64def to_token(amount_units):65return amount_units / float(10 ** MIR20.DECIMALS)