migration
migration copied to clipboard
dao-params.json Deserialize->Validate->Serialize Workflow
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 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 script.
I've tried to remedy this a bit by creating the sanitize.js script that defines a jsonschema 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. These forms can be used to deserialize -> validate -> serialze. I propose that we adopt this form library.
Here's the DAO Form class which implements the schema.
Here's an example usage:
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