Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

use strictyaml for parsing dotrain yaml #1035

Open
hardyjosh opened this issue Dec 1, 2024 · 0 comments
Open

use strictyaml for parsing dotrain yaml #1035

hardyjosh opened this issue Dec 1, 2024 · 0 comments

Comments

@hardyjosh
Copy link
Contributor

hardyjosh commented Dec 1, 2024

as part of #965, we want to switch over to using strictyaml for our dotrain order frontmatter.

https://docs.rs/crate/strict-yaml-rust/latest

the current implementation attempts to parse our yaml into more complex types, with some undesired effects that we can't really control. whereas strictyaml only has strings, arrays and maps.

this means we'll need to do all additional parsing ourselves.

this implementation probably looks something like:

  • removing ConfigSource and Config entirely
  • instead, creating a OrderbookYaml and DotrainOrderYaml struct (see the spec)
  • these will use strictyaml to create a flat struct that matches the structure of the spec (i.e. in a Deployment the order field is a string with the name of the order, not an Order). other types would be parsed (i.e. a Vault vault-id would be U256.
  • these structs would be able to take a Vecof yamls that would be merged (i.e. a DotrainOrderYaml could be composed with an OrderbookYaml, like we do now with 'settings' and orders)
  • implementing getters that will retrieve nested data on-demand according to the spec
  • implementing setters that will update nested data (i.e. updating a gui deployment's order's first input's token's address)
  • a serialisation function to convert the DotrainOrderFrontmatter struct back into a string, such that deserialising would produce the same struct
  • a validation function (?)

the goals for this revised implementation are:

  • explicit parsing of the yaml into types other than strings
  • a controlled entrypoint into the data, so for example we can do on the fly token replacement using ${order.input[0].token.address} syntax and know it will be enforced everywhere
  • one source of truth when working with frontmatters (at the moment having both ConfigSource and Config causes issues where we have to retain both)
  • always being able to go back to a string without losing any data integrity

other considerations:

  • strictyaml doesn't contain anchors/refs, so we can't use that functionality as we were thinking. but it was pretty awkward anyway (ie required stringly merging yamls which was getting kinda hacky)
  • some of this could be done incrementally, for example plots could be re-emitted as a string and parsed using the existing serde_yaml implementation
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant