# Sunshine Web3 Grant Application 2 (Draft) Sunshine is applying for a follow-up grant to fund our ongoing contributions to the Substrate, Rust, and Flutter ecosystems. Our user research has demonstrated significant ecosystem interest among Web3 grant recipients for grant and bounty infrastructure to outsource developer tasks. We have been public about our intentions to build Gitcoin + Aragon on a substrate chain. The enclosed grant funds our immediate development to realize that vision and, in the process, continue building useful infrastructure for all Substrate-based chains. ## Past Work for the Web3 Foundation We wrote a [recent blog post](https://meta5.world/posts/ysunshine) listing open source contributions funded by our first Web3 grant. Highlights include * 7 governance pallets, configured into a runtime and node to express a Substrate DAO Chain * Rust client and CLI for interacting with the node * [`substrate-subxt`](https://github.com/paritytech/substrate-subxt/) contributions to support native Rust clients and light clients (w/ 2 Parity projects now using substrate-subxt for this purpose -- ledgeracio, cargo contract) * Rust client which uses [`ipfs-embed`](https://github.com/ipfs-rust/ipfs-embed) for storage of data not necessary for Substrate runtime storage * including tooling around `ipfs-embed` to facilitate error handling and improve the overall API * Rust-Dart FFI to call Rust client code from Flutter Dart User Interface * with intermediate infrastructure open sourced for the wider Rust and Flutter ecosystems * native keystore supports modern key management i.e. key rotation Most of this work fell outside the scope of our first grant, but we never let that limit what we built. We will continue to exceed expectations and we are just getting started. ## Team <a name = "team"></a> [Amar](https://github.com/4meta5) started and maintained the [Substrate Recipes](https://substrate.dev/recipes/) as an employee at Parity. He wrote the [`substrate-bounty`](https://github.com/sunshine-protocol/sunshine-bounty) runtime, node, client, and CLI under Sunshine's first grant. He is an experienced substrate runtime developer and the CEO of Sunshine. [David](https://github.com/dvc94ch) worked on substrate core development as an employee at Parity. He is the lead maintainer of [`ipfs-embed`](https://github.com/ipfs-rust/ipfs-embed) and contributes upstream often to [`substrate-subxt`](https://github.com/paritytech/substrate-subxt/) to meet Sunshine's Rust client requirements. David recently won the surprise category of the Polkadot Launch Hackathon with [`sunshine-identity`](https://github.com/sunshine-protocol/sunshine-identity), an implementation of [Keybase's Local Key Security](https://book.keybase.io/docs/crypto/local-key-security) on substrate, using `ipfs-embed`. [Shady](https://github.com/shekohex) is an experienced Typescript, Flutter, and Rust developer with contributions to many open source projects (i.e. [`nest-access-control`](https://github.com/nestjsx/nest-access-control/graphs/contributors)). He is a pioneer in Rust-Dart FFI development with generic components released alongside his work on the Sunshine Flutter infrastructure i.e. [`flutterust`](https://github.com/shekohex/flutterust). ## Grant Proposal We are asking for the Web3 Foundation to fund the following infrastructure: 1. Sunshine DAO governance runtime development, which has the immediate purpose of realizing democratic decision-making structures to govern bounties and grants in the Substrate ecosystem 2. Substrate client development on [`substrate-subxt`](https://github.com/paritytech/substrate-subxt/) (used by Parity projects - `ledgeracio`, `cargo contract`) 3. Substrate off-chain storage development on [`ipfs-embed`](https://github.com/ipfs-rust/ipfs-embed) 4. Rust-Flutter infrastructure to support cross-platform native applications that talk to `substrate-subxt` clients Our infrastructure development is informed by our product requirements. This raises the standard for our deliverables. Not only do we have to meet the written requirements, but we also have to handle the unexpected problems that arise during practical software development and deployment. A major theme in this grant application is **Bots**. Milestones (1), (3), and (6) include examples to demonstrate using our Rust client (powered by `substrate-subxt`) to make direct calls to the APIs for Github, Twitter, and Telegram respectively. ## Milestones All deliverables will include testing along with directions to run the code and tests. All code will be delivered upon request in a docker container. ### Milestone 1 * github bot to watch on-chain bounty state and comment in the relevant github issue about changes to the amount posted (like Gitcoin bot) * includes improvements to substrate-subxt API for subscribing to event streams (see [issue](https://github.com/paritytech/substrate-subxt/issues/141)) * `flutter-signer`: native Dart substrate signer for Flutter applications, similar to [react-native-substrate-signer](https://github.com/paritytech/react-native-substrate-sign) * includes tool for generating Dart FFI bindings to C Header files * includes tool for running multithreaded Rust in the Dart VM * includes logger for Flutter applications to monitor Rust interactions ### Milestone 2 * native Dart telemetry for substrate light clients to show loading bar progress during chain sync * improves usability for `flutter-signer` and all other infrastructure that uses our Rust-Flutter stack * `sunshine-org` and `sunshine-vote` stress testing with CLI demo to show many orgs the chain can support and how many votes in a given time period * includes benchmarking of both modules based on estimated cost/complexity of their runtime methods * demo will be recorded and may be presented at a future conference to showcase the power of substrate in the context of our DAO chain implementation * identity protocol for provisioning devices and changing passwords across login sessions (extending [sunshine-identity](https://github.com/sunshine-protocol/sunshine-identity)) ### Milestone 3 * Twitter bot to watch votes on-chain and tweet out results (in Flutter, listening to a Rust client) * [borda count](http://proceedings.mlr.press/v97/kahng19a/kahng19a.pdf) module for leadership selection (as the link notes, borda count is resilient to noise and useful for general purpose leadership selection on other substrate chains) * the implementation will inherit the existing `sunshine-org` pallet and, therefore, does not follow the same structure as `elections-phragmen` * `sunshine-identity` support for teams and, in particular, off-chain signature aggregation (so teams can collect consent off-chain and submit a proof on-chain); includes cache for proofs in ipfs-embed (in the native keystore) * off-chain signature aggregation implementation will be useful for other substrate chains with similar use cases ### Milestone 4 * WASM web app that talks directly to `substrate-subxt` light client to fetch on-chain data (part 1) * demo will display vote information alongside participation requirements and instructions to install the Flutter application on Android and iOS to participate * this infrastructure will be useful for other projects that use `substrate-subxt` and are looking for a web framework alternative to polkadot-js (with more memory and computation with WASM) * follow/unfollow feature for sunshine-identity users to keep local identity data available * includes ipfs-embed DHT features like nat traversal and implementing the autonat protocol to verify nat traversal ### Milestone 5 * WASM web app that talks directly to `substrate-subxt` light client to authenticate users and make requests to the client (part 2) * demo includes ability to participate in votes directly using the wasm application * this will be useful for other projects that use substrate-subxt and want to go the WASM web route instead of polkadot-js * sunshine governance runtime improvements and extensions * enforced term limits for representative selection (borda count election automatically dispatched every term period) * sortition to randomly select a representative for any group (_random leader selection_) * threshold-based revocation to allow any group to revoke delegation and re-select a leader in the context of power abuse * ability for groups to choose their leadership selection algorithm between (1) borda count (2) random leader selection among defined group * with or without threshold-based revocation * `ipfs-embed` demo for decreasing substrate runtime storage requirements by storing a merkle root on-chain and verifying data inclusion in ipfs blocks off-chain ### Milestone 6 * Telegram bot for reporting results of on-chain votes based on event subscriptions configured by the chat admin * button for github repos to accept donations that are automatically distributed to team members in proportion to ownership set in `sunshine-org` * includes `sunshine-donate` module and submission flow of ownership proportions by the repo owner (in Flutter UI) * substrate-subxt improvements to runtime error parsing and, more specifically, proc-macro error handling ### Time Estimates All 3 developers listed under [Team](#team) will be working full time on this project to complete the 6 milestones in 6 months. Milestones 1, 3, and 4 will each require an estimated 2-4 weeks of of full-time work. Milestones 2, 5, and 6 will each require an estimated 4-6 weeks of full-time work.