daostack / daostack/migration

dao-params.json Deserialize->Validate->Serialize Workflow

Open
#297 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
17
Forks
16
PR merge metrics
No merged PRs in 30d

Description

Currently the dao-params.json schema is loosely defined. In order for developers to understand the full schema, they could look at the [example dao-params.json](https://github.com/daostack/migration/blob/master/migration-params.json) in the repo, but this lacks completeness. To gain a full understanding they would have to look through how the dao-params are being used in the [`migrate-dao.js`](https://github.com/daostack/migration/blob/master/migrate-dao.js) script.

I've tried to remedy this a bit by creating the [`sanitize.js`](https://github.com/daostack/migration/blob/master/sanitize.js) script that defines a [`jsonschema`](https://json-schema.org/) for dao-params, but this is still a bit incomplete and hard to work with IMO. Reasons:
- I've encountered issues using jsonschema's node package, where it does not traverse the document's AST and apply the schema correctly.
- jsonschema doesn't provide a solution for serializing / deserializing.
- jsonschema schemas defined in javascript do not give you typescript types to utilize else where.

In the DAOcreator I've solved the above by creating a serialize of forms that implement the dao-params schema. This form library uses an extended version [`formstate`](https://formstate.github.io/#/). These forms can be used to deserialize -> validate -> serialze. I propose that we adopt this form library.

Here's the [DAO Form](https://github.com/dOrgTech/DAOcreator/blob/master/packages/lib/src/forms/dao/DAOForm.ts) class which implements the schema.

Here's an example usage:
```typescript
const daoParams = `{
...json string
}`

const dao = new DAOForm()
// deserialize
dao.fromJson(daoParams)
// modify
dao.$.orgName.value = 'something'
dao.$.founders.$.value = []
// validate
const res = await dao.validate()
console.log(res.hasError) // true
console.log(res.error) // founders must contain at least 1 item
// serialize
const json = dao.toJson()
```

Custom validators can be written to verify single properties, or cross verify multiple properties together. This is used in the DAOcreator to ensure these conditions for the genesis protocol are met: https://github.com/daostack/infra/blob/a09e9a524fbacc9fb39d5d1de8986dcf45c4889c/contracts/votingMachines/GenesisProtocolLogic.sol#L259-L264

Contributor guide

No contributing guide indexed for this repository

Research direction

Start by reading sanitize.js and migrate-dao.js alongside migration-params.json to map the current DAO parameters and validation flow. Then compare the proposed DAOForm.ts and its deserialize, validate, and serialize usage; done should mean the schema is complete and the workflow is usable for DAO parameters.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, typescript
Domain
blockchain, tooling
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.