ref-fvm
ref-fvm copied to clipboard
introduce an example ERC20-like token actor
This is an extremely rough-and-ugly implementation of an ERC20-like native token actor for the Filecoin network. It uses no SDK sugar (because none exists yet), neither for syscalls nor or error handling.
Supported features
The current code supports token symbols, names, maximum supplies, and simple transfers. It DOES NOT YET support authorizations for delegate spending.
On developer experience
As stated above, this is code is still ugly. The developer experience will improve dramatically as the FVM project advances towards Milestone 2.
The author deliberately didn't use this opportunity to improve the SDK. Instead, he chose to implement things low-level to create a baseline of where we are. As we introduce better DX, this actor will evolve and benefit.
NOTE: There is some pre-existing sugar in the actor/runtime module that could facilitate things slightly easier here, but this actor does not use it to avoid dragging in unnecessary dependencies (related to built-in actors). The upcoming sugar will eventually be provided by the Rust SDK, and not the built-in actors toolkit.
Boilerplate
The following responsiblities are taken care of here, but they are absolutely boilerplate, and should eventually be superseded by clever sugar in the form of proc macro attributes.
- State loading.
- State mutations.
- Method dispatch.
- Deserialization of parameters.
- Serialization of return data.
Addressing
For simplicity, this actor uses ActorIDs in the balances and allowances HAMT (map) keys. This poses two problems:
- A sender cannot send tokens to an inexistent account actor.
- This actor is not reorg-safe (ActorIDs can change in the chain gets reorg-ed).
We could do sophisticated things here to solve for these problems, by associating balances to class-{1,2,3} addresses only, and rejecting calls with class-0 (ID addresses).
However, all of this will change when we introduce class-4 addresses (reorg stable universal addresses), so it's not worth the complexity now, as this actor only exists for illustration purposes.
⚠️ 🐉 🔥 ☠️ NOT MEANT FOR PRODUCTION USAGE
This actor should NEVER be deployed on the Filecoin network. It is purely meant for illustration and test purposes.
TODO
- [x] Integration hooks in the FVM to load custom code (test mode only).
- [x] Integration tests that deploy the actor into the FVM and play with it.