create account

Dapp-a-day 6: Upgradeable Tokens by nikolai

View this thread on: hive.blogpeakd.comecency.com
· @nikolai · (edited)
$67.40
Dapp-a-day 6: Upgradeable Tokens
![Nexus Logo](https://i.imgur.com/JoJ8cXZ.png)

**Each weekday leading up to devcon2, Nexus will highlight a dapp, library, or package (something with a `dappfile`) as a promotion of our toolchain and as case studies for other developers. [Yesterday's Post](https://steemit.com/ethereum/@nikolai/dapp-a-day-5-easy-multisig)**

`ds-token` is a framework for writing upgradeable tokens. It depends on [`ds-auth`](https://github.com/nexusdev/ds-auth) and implements [`erc20`](https://github.com/nexusdev/erc20).

https://github.com/nexusdev/ds-token

It achieves two seemingly opposing goals:

* Keep the "interface" address fixed - don't burden consumers with your update logic (e.g. registry lookups or following an update chain).
* Allow the behavior to be changed (with the ability to lock down, of course), and make it painless.

This is done by splitting the token contract into 3: A "Frontend", a "Controller", and a "Datastore". These are all `DSAuth` (`DSAuthorized`), they look up to a `DSAuthority` for access control.

The frontend has `erc20` function definitions as well as `emit*` event callback functions.

The controller has implementations of the `erc20` functions extended to also accept the frontend's `msg.sender` as an argument (ERC20 semantics depend on msg.sender).

The datastore holds all app state and has only dumb getters and setters and makes logic updates significantly easier.

This design is partially an artifact of the days before `DELEGATECALL` and usable libraries, which could arguably reduce this to a 2-contract system. But still, separating the entrypoint and logic controller makes me less nervous about accidentally butchering state.

There is a DSToken "installer" (a "smart factory") which instantiates a token that is functionally equivalent to ERC20Base. It installs a token "into" an existing `DSBasicAuthority`.

With `ds-token` under our belt, we can explore applications that *use* tokens as well as applications that *are* tokens. Wow, coins!
👍  , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , , ,
properties (23)
authornikolai
permlinkdapp-a-day-6-upgradeable-tokens
categoryethereum
json_metadata{"tags":["ethereum","dapp","blockchain","cryptocurrency"],"image":["https://i.imgur.com/JoJ8cXZ.png"]}
created2016-08-15 14:56:09
last_update2016-08-15 14:57:42
depth0
children3
last_payout2016-09-15 18:28:48
cashout_time1969-12-31 23:59:59
total_payout_value50.795 HBD
curator_payout_value16.606 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length1,991
author_reputation9,571,877,600,096
root_title"Dapp-a-day 6: Upgradeable Tokens"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id817,896
net_rshares18,974,408,119,279
author_curate_reward""
vote details (43)
@achim86 ·
http://www.mikrocontroller.net/attachment/68905/thanks-for-the-info.jpg
👍  
properties (23)
authorachim86
permlinkre-nikolai-dapp-a-day-6-upgradeable-tokens-20160815t150150349z
categoryethereum
json_metadata{"tags":["ethereum"],"image":["http://www.mikrocontroller.net/attachment/68905/thanks-for-the-info.jpg"]}
created2016-08-15 15:00:54
last_update2016-08-15 15:00:54
depth1
children0
last_payout2016-09-15 18:28:48
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length71
author_reputation46,760,156,630,779
root_title"Dapp-a-day 6: Upgradeable Tokens"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id817,969
net_rshares308,551,544
author_curate_reward""
vote details (1)
@bitcoinsulting ·
Thanks, this will help to understand more about the "token" concept and how to achieve some bindings to a "Mothercoin"
properties (22)
authorbitcoinsulting
permlinkre-nikolai-dapp-a-day-6-upgradeable-tokens-20160816t150733226z
categoryethereum
json_metadata{"tags":["ethereum"]}
created2016-08-16 15:07:33
last_update2016-08-16 15:07:33
depth1
children0
last_payout2016-09-15 18:28:48
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length118
author_reputation619,517,583,858
root_title"Dapp-a-day 6: Upgradeable Tokens"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id835,450
net_rshares0
@linkback-bot-v0 ·
<div>  <p>  This post has been linked to from another place on Steem.  </p>  <ul>        <li>      <a href="https://steemit.com/ethereum/@nexusdev/dapp-a-day-16-ds-burner"> Dapp-a-day 16: DS-burner </a>      by      <a href="https://steemit.com/@nexusdev">  @nexusdev </a>     </li>        <li>      <a href="https://steemit.com/ethereum/@dbrock/dapp-a-day-16"> Dapp-a-day 16 </a>      by      <a href="https://steemit.com/@dbrock">  @dbrock </a>     </li>        <li>      <a href="https://steemit.com/ethereum/@nexusdev/dapp-a-day-13-solidity-quirks"> Dapp-a-day 13: Solidity Quirks </a>      by      <a href="https://steemit.com/@nexusdev">  @nexusdev </a>     </li>        <li>      <a href="https://steemit.com/ethereum/@nexusdev/dapp-a-day-12-ds-base"> Dapp-a-day 12: DSBase – a reasonable base class </a>      by      <a href="https://steemit.com/@nexusdev">  @nexusdev </a>     </li>        <li>      <a href="https://steemit.com/ethereum/@nexusdev/dapp-a-day-11-whitelist-boring"> Dapp-a-day 11: Whitelist (Boring!) </a>      by      <a href="https://steemit.com/@nexusdev">  @nexusdev </a>     </li>      </ul>  <p> Learn more about  <a href="https://steemit.com/steem/@ontofractal/steem-linkback-bot-v0-3-released">    linkback bot v0.3</a>   </p>   <p>Upvote if you want the bot to continue posting linkbacks for your posts. Flag if otherwise.   Built by @ontofractal</p></div>
properties (22)
authorlinkback-bot-v0
permlinkre-nikolai-dapp-a-day-6-upgradeable-tokens-linkbacks
categoryethereum
json_metadata{}
created2016-09-10 19:45:57
last_update2016-09-10 19:45:57
depth1
children0
last_payout2016-09-15 18:28:48
cashout_time1969-12-31 23:59:59
total_payout_value0.000 HBD
curator_payout_value0.000 HBD
pending_payout_value0.000 HBD
promoted0.000 HBD
body_length1,389
author_reputation1,915,954,976,722
root_title"Dapp-a-day 6: Upgradeable Tokens"
beneficiaries[]
max_accepted_payout1,000,000.000 HBD
percent_hbd10,000
post_id1,199,947
net_rshares0