Created
August 18, 2017 17:28
-
-
Save danfinlay/7edece7e3d80ca2976c2b9a9948b47a0 to your computer and use it in GitHub Desktop.
Rough draft of a meme market ENS registrar system. You'd register a top-level ENS name for the parent one, and it would allocate its child names according to the desires of its token holders, thus minting new child registrar tokens.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| contract MalleleRegistrar is HumanStandardToken, EnsRegistrar { | |
| // Map subnode namehashes to child instances of MalleleRegistrar. | |
| mapping(bytes32 => address) subMalleles; | |
| mapping(address => bytes32) balances; | |
| uint currentPrice = 1; | |
| uint priceIncrease = 1; | |
| address baseCurrencyToken; | |
| function MalleleRegistrar (uint initialPrice, | |
| uint _priceIncrease, | |
| address _baseCurrencyToken) { | |
| currentPrice = initialPrice; | |
| priceIncrease = _priceIncrease; | |
| baseCurrencyToken = _baseCurrencyToken; | |
| } | |
| function buyIn( subnameHash ) onlyAcceptTokens(baseCurrencyToken) { | |
| uint tokensDeposited = getReceivedTokens(); // Hypothetical, just imagine for now. | |
| uint startPrice = currentPrice; | |
| uint endPrice = currentPrice + tokensDeposited; | |
| uint avgPrice = (startPrice + endPrice) / 2; | |
| balances[msg.sender] += avgPrice * tokensDeposited; | |
| currentPrice = endPrice; | |
| } | |
| function sellOut(uint qtyDesired) { | |
| if (balances[msg.sender] < qtyDesired) throw; | |
| uint startPrice = currentPrice; | |
| uint endPrice = currentPrice - qtyDesired; | |
| uint avgPrice = (startPrice + endPrice) / 2; | |
| balances[msg.sender] -= avgPrice * tokensDeposited; | |
| currentPrice = endPrice; | |
| sendReserveTokensTo(msg.sender); | |
| } | |
| function spawnSubMallele (bytes32 namehash, uint purchaseSize) { | |
| if (subMalleles[namehash]) revert; // Do not overwrite existing malleles. | |
| // Malleles are forever. | |
| subMalleles[namehash] = new MalleleRegistrar(1, 1, this.address); | |
| subMalleles[namehash].buyIn.delegate_call(namehash, purchaseSize); | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment