Skip to content

Instantly share code, notes, and snippets.

@nicosantangelo
Last active July 5, 2018 12:15
Show Gist options
  • Save nicosantangelo/0a5060f2cdc19109686c494645db2975 to your computer and use it in GitHub Desktop.
Save nicosantangelo/0a5060f2cdc19109686c494645db2975 to your computer and use it in GitHub Desktop.
Decentraland dapp tools/ideas

Index

dcl-contracts

The main idea is to remove the coupling between contracts and decentraland-eth. To do this, we propose a new clien which does two main things:

  1. Generates a typescript contract interface for a given ABI. It'll look something like this
|____contract-1
|  |____artifact.json
|  |____index.d.ts
|  |____index.ts
  1. Publishes the contract interface as an npm package

  2. Extra: Use truffle as a peer dependency and add a compilation step to the process. That way it can be run directly on a Contract.sol.

Using dcl-contracts

Compile an abi:

$ cd contract-repo/
$ ls
  .
  |____build/
  |____contracts/
  |____migrations/
  |____(...)

$ dcl-contracts compile build/contracts/Contract1.json
#                          ^ artifact/abi file
# Result: 
#   |____Contract1
#   |  |____artifact.json
#   |  |____index.d.ts
#   |  |____index.ts

Publish a new Contract.sol:

$ cd contract-repo/
$ ls
  .
  |____build/
  |____contracts/
  |____migrations/
  |____(...)

$ dcl-contracts publish contracts/Contract1.sol   @decentraland-contracts/contract-1     1.0.0
#                          ^ src file               ^ npm name                            ^ version (shorthand major,minor,pacth).

Using on a js file:

// npm install --save @decentraland-contracts/marketplace

import Marketplace from '@decentraland-contracts/marketplace'

eth.connect({
    contracts: [new Marketplace('0x2123')]
})

eth.getContract('Marketplace').publish(/* Typed!! */)

Notes

  • We probably want to use a project like abi-gen or TypeChain, at least to get some ideas
  • Solve npm permissions
  • Consider supporting semantic versioning. For example: It should allow major as a version argument which will in turn fetch the current version and add a major to it.
  • Define suitable flags for the command line arguments

dcl-blockchain-monitor

We need to simply and abstract the marketplace monitor. The idea is to have a plug and play monitor which allows for different uses.

The main changes are:

  • Allow for custom handlers (already possible here)
  • Allow for custom processEvents (not possible at the moment, somewhat hardcoded here)
  • Add a reducer-like logic to processEvents. The idea
  • Maybe simplify the way flags work. Now it uses commander thru decentraland-server. Example here

dcl-dapp-scripts

Add common scripts to a single repo. Inspired in part on how react-scripts works.

For now the idea is to extract away a few recurring scripts.

Some of them currently live on dapp-boilerplates script folder and should be replaced there:

  • npm run translate: Uses the default translation to fill the other locales. Expects a src/Translation model. Depends on [decentraland-commons](https://github.com/decentraland/decentraland-commons)
  • npm run migrate: The current migrate script is based node-pg-migrate. At the time of writing, it is coupled with the folder structure we use.
  • npm run create-model: Create the files and folder structure for a new database backed model. At the time of writing, it is coupled with the folder structure we use.

Others still need some refactoring and live on the marketplaces script folder

  • npm run seed: This script needs a small re-write. We need to migrate it to Typescript first. Then we need to take care of the getRandomColumnValue function which is coupled to the Marketplace. One option is to leave the more generic column names and just delete the others. On top of that we can export a seed function and allow the user to provide a custom getRandomColumnValue to use programatically.

dcl-create-dapp

This should serve as the main hub or entry point to start new Decentraland dapps. It's not a flesh out idea yet but in principle it should encapsulate:

dcl-dapp-boilerplate

The idea (for now) here is to use the boilerplate as a starting point for new libs. That doesn't mean the boilerplate shouldn't exist, but rather that it should be composed of many different libs instead of static code.

There's a ton of work still to be done, but one for reference this are some of the extraible parts of the codebase we've encountered:

  • Translations (front+back)
  • Storage management (front)
  • Trasactions management (front)
  • Analytics (front. Missing, needs to be extracted from the marketplace)
  • Loading state (front)
  • Api script (front. lib/api.ts)
  • Wallet Component and state (front)
  • Shared code between front+backend (Missing, needs to be extracted from the marketplace)

Reference

Reference for the current libs we're using on Decentraland Dapps and roughly what they do

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment