Futarchy-Polkadot-Hackathon-2023 / Things

Things
3 stars 0 forks source link


Logo

Futurachy - Quickstart

Futurachy We're incentivising altruistic governance!
Quickstart is a simplified version of Futurachy.

Guided-Quickstart Video · Report Bug · Request Feature

Table of Contents
  1. About The Project
  2. Getting Started
  3. Contact
  4. Acknowledgments

About The Project

Screenshot

screenshot

Description

We're incentivising altruistic governance!

This is a Quickstart of the Project Futurachy.

Quickstart is a simplified version of the inner workings.

Summary

  1. It spins up a Indexer, which graps the latest proposal from the Zeitgeist Chain.
  2. It creates a graphQL endpoint.
  3. It gets the Data through the GraphQL Endpoint.
  4. It fetches the title from polkassembly based on the graphQL data.
  5. It converts the title in question, description and slug.
  6. It creates a market from question, description and slug.
  7. The created Market created a market Id.
  8. It converts converts marketId to a marketLink.
  9. It posts a comment in polkassembly with a link to the newly created Market.

(back to top)

Built With

NodeJs Subsquid Zeitgeist

(back to top)

Getting Started

Follow README or Follow via Video.

Quick Start

Terminal A

 cd ./00-squidServer
 npm install
 source .env
 npx sqd up
 npx sqd process 

Terminal B

cd ./00-squidServer
npx sqd server

Terminal C

npm install
mv ./env-example ./env
echo "seed=YOUR_SEED_WITH_ZTG_TOKENS_ON_BATERRY_TEST_NEXT" >> .env
node main.js

Output:
Screenshot

Deep Dive

  1. check if node is installed. If not download it from NodeJs.org.
node --version
> v18.13.0
  1. change directory to ./00-squidServer
cd ./00-squidServer
  1. rename ./env-example to ./env
mv ./env-example ./env
  1. source your ./env
source ./env
  1. install packages, create ./node_modules folder
npm install
  1. set up subsquid indexer.
npx sqd up
npx sqd codegen
npx sqd migration:generate
  1. run the mirgation process
npx sqd process
  1. Amazing. This terminal will be block from now on.
  2. Open up a fresh new Terminal. In the new terminal navigate to the ./00-squidServer
  3. start the graphQL server
npx sqd serve
  1. Got to http://localhost:4350/graphql
  2. Select or paste this query and run it.
query MyQuery {
  proposals(limit: 1)
}

This is my current output, you will see a slidly diffrent output. Because new proposal will come in daily.

Output
{
  "data": {
    "proposals": [
      {
        "id": "0015438492-000039-c308a"
      }
    ]
  }
}
  1. Amazing. Now we have our indexer and our graphQL Server running. This terminal will be block from now on.
  2. Open up a 3rd Terminal and navigate to the root folder.
  3. run tree and you should see the following
tree -L 1
Output
.
├── 00-squidServer
├── 01-getData
├── 02-createMarket
├── 03-postComment
├── README.md
├── main.js
├── package.json
├── screenshot.png

6 directories, 7 files
  1. Install packages
npm install
  1. rename ./env-example to ./env
mv ./env-example ./env
  1. paste seed in your Dev Account with Zeitgeist Token of the Battery Testnet into the .env
echo "seed=YOUR_SEED_WITH_ZTG_TOKENS_ON_BATERRY_TEST_NEXT" >> .env
  1. source your ./env
source ./env
  1. run the main script.
node ./main.js
  1. You see the following outcome.
    Output
    {
    body: '{"query":"query MyQuery {\\n  proposals(limit: 1) {\\n    proposalIndex\\n  }\\n}\\n","variables":null,"operationName":"MyQuery"}'
    }
    ...getData()...
    {
    question: 'Will proposal with Indes of 229 resolve?',
    description: '#229 Treasury Proposal: Polkawatch, Decentralization Analytics, Continued Operation and Development',
    slug: '#229 Treas',
    proposalIndex: 229
    }
    ---------↓-----------
    {
    question: 'Will proposal with Indes of 229 resolve?',
    description: '#229 Treasury Proposal: Polkawatch, Decentralization Analytics, Continued Operation and Development',
    slug: '#229 Treas',
    proposalIndex: 229
    }
    ...createMarket()...
    {
    proposalIndex: '229',
    comment: 'A prediction market is created.🗽 \n' +
    '\n' +
    'Go to [Zeitgeist App - Market Link](https://app.zeitgeist.pm/markets/234) \n' +
    '\n' +
    ' ⚠️ Currently only on the Battery-Testnet of Zeitgeist ⚠️ '
    }
    ---------↓-----------
    {
    proposalIndex: '229',
    comment: 'A prediction market is created.🗽 \n' +
    '\n' +
    'Go to [Zeitgeist App - Market Link](https://app.zeitgeist.pm/markets/234) \n' +
    '\n' +
    ' ⚠️ Currently only on the Battery-Testnet of Zeitgeist ⚠️ '
    }
    ..postComment()...
    { status: 'true', link: 'https://polkadot.polkassembly.io/post/1617' }

  1. Lets look at the ./main.js to see the actually code
    cat ./main.js
Output
  import { getData } from "./01-getData/01-getData.js";
  import { createMarket } from "./02-createMarket/02-createMarket.js";
  import { postComment } from "./03-postComment/03-postComment.js";

async function main(dataInput) {
let resGetData = await getData(dataInput)
let resCreateMarket = await createMarket(resGetData)
let resPostComment = await postComment(resCreateMarket);
}

main({ body: "{\"query\":\"query MyQuery {\\n proposals(limit: 1) {\\n proposalIndex\\n }\\n}\\n\",\"variables\":null,\"operationName\":\"MyQuery\"}", })

  
Explainer
  1. There is a main function
  2. The main function runs 3 functions.
  3. The main function runs each function one after the other. (async)
  4. First getData() gets called.
  5. getData() takes an input.
  6. The input is a hardcoded stringfy version of our previously callded graphQL query.
  7. The output of getData() gets stored in resGetData variable.
  8. The second function is called createMarket(.
  9. createMarket() gets called after getData() is executed.
  10. createMarket takes the output of getData as an input.
  11. The output of createMarket() gets stored in resCreateMarket variable.
  12. The third function is called postComment()
  13. postComment() gets called after createMarket() is executed.
  14. postComment takes the output of createMarket() as an input.
  15. The output of postComment() gets stored in resPostComment variable.
  16. Thats the whole function declartion of main.js
  17. the main function gets called after the declartion.
  18. The main function takes a stringfy version of our graphQL query as an input.
TLDR
  1. getData() fetches Data.
  2. createMarket() creates a Market.
  3. postComment posts a comment on Polkassembly.
  1. Lets run our ./main.js again and break it down.
node ./main.js
  1. Section 1 - Breakdown

    Output - Section 1
    {
    body: '{"query":"query MyQuery {\\n  proposals(limit: 1) {\\n    proposalIndex\\n  }\\n}\\n","variables":null,"operationName":"MyQuery"}'
    }
    ...getData()...
    {
    question: 'Will proposal with Indes of 229 resolve?',
    description: '#229 Treasury Proposal: Polkawatch, Decentralization Analytics, Continued Operation and Development',
    slug: '#229 Treas',
    proposalIndex: 229
    }
    
    Breakdown - Section 2
    1. Section 1 takes a graphQL Query as an Input
    2. Runs getData().
    3. It returns another Object.
    4. The object has a question, description, slug, and a propsalIndex
  2. Section 2 - Breakdown

Output - Section 2
{
  question: 'Will proposal with Indes of 229 resolve?',
  description: '#229 Treasury Proposal: Polkawatch, Decentralization Analytics, Continued Operation and Development',
  slug: '#229 Treas',
  proposalIndex: 229
}
...createMarket()...
{
  proposalIndex: '229',
  comment: 'A prediction market is created.🗽 \n' +
    '\n' +
    'Go to [Zeitgeist App - Market Link](https://app.zeitgeist.pm/markets/234) \n' +
    '\n' +
    ' ⚠️ Currently only on the Battery-Testnet of Zeitgeist ⚠️ '
}
Breakdown - Section 2
  1. Section 2 takes an object as an Input.
  2. The Object contains a question, description, slug and a proposal Index.
  3. Runs getData().
  4. It returns another Object.
  5. The object has a proposalIndex and a comment.
  1. Section 3 - Breakdown
Output - Section 3
{
  proposalIndex: '229',
  comment: 'A prediction market is created.🗽 \n' +
    '\n' +
    'Go to [Zeitgeist App - Market Link](https://app.zeitgeist.pm/markets/234) \n' +
    '\n' +
    ' ⚠️ Currently only on the Battery-Testnet of Zeitgeist ⚠️ '
}
..postComment()...
{ status: 'true', link: 'https://polkadot.polkassembly.io/post/1617' }
Breakdown - Section 3
  1. Section 3 takes an object as an Input.
  2. The Object contains a proposalIndes and a comment.
  3. Runs postComment().
  4. Spit another Obeject out.
  5. The object has a question, description, slug, and a propsalIndex.
  1. This is the simplistic showcase of Futurachy.
  2. If you are curious, take a look at each folder.
ls -la ./00-squidServer
ls -la ./01-getData
ls -la ./02-createMarket
ls -la ./03-postComment
  1. The scripts are following the following convention.
|- DataInput
|- DataOutput
|- Function Declartion
|- Function Call
|- Export
The Code Convention
  • Every script has a one specific purpose.
  • In MockInput / MockOutput you can see what each script takes as a argument.
  • The function declartion is the main section. It cointains the main logic.
  • The function call contains a running example of how to call it. By default its comment out.
  • The export section contains all exports.
    1. Thanks for following along. : )

    (back to top)

    Contact

    Sergey Gerodes - LinkedIn
    K Gunjan - gunjan.cn@gmail.com - LinkedIn
    Frank Bevr - frank_dierolf@web.de - Discord: FrankBevr#9593
    Morkeltry - @morkeltry - He will find you

    Project Link: Futurachy

    (back to top)

    Acknowledgments

    (back to top)