Dapp-a-day 16

in #ethereum8 years ago

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. Previous post

Today's dapp is pretty simple, but also kind of interesting. It's called ds-burner. It's a package that helps you burn your tokens in a safe and convenient way, in case you have too many of them.

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

The file burner.sol defines the main burner. It specializes in just one particular kind of token, but it makes sure that any tokens of that kind that it receives will eventually get burned into oblivion.

How does it do this? Well, it needs to have a reference to something called a "token supply manager," which is the other thing that this package contains. The token supply manager in turn (supply_manager.sol) is just a wrapper around a token balance database, which is a basic token building block from the ds-token repository (see Dapp-a-day 6).

Anyone who is able to call the supply manager is able to create or destroy whatever amount of tokens they want, so access to the supply manager is restricted using DSAuth (see Dapp-a-day 4).

To use a burner, a supply manager and a balance database together, the burner needs permission to call the manager, and the manager needs permission to call the database. The burner, though, is unrestricted, which is kind of the whole point: anyone is able to use the burner to destroy tokens that they themselves own.

You can either call the burn(uint) method to have the burner pull tokens from you and burn them immediately, or you can transfer tokens to the burner directly using the ERC20 transfer() function and wait for someone to call the burn() method, which simply burns all the tokens that the burner currently has in its possession.

So then why would you want to "burn" tokens in the first place, you ask?

Well... that's an excercise for the reader.