{"id":26497683,"url":"https://github.com/robin-thomas/flyt","last_synced_at":"2025-03-20T13:57:23.119Z","repository":{"id":44838132,"uuid":"215407990","full_name":"robin-thomas/flyt","owner":"robin-thomas","description":null,"archived":false,"fork":false,"pushed_at":"2023-09-06T07:00:46.000Z","size":3777,"stargazers_count":8,"open_issues_count":1,"forks_count":2,"subscribers_count":3,"default_branch":"master","last_synced_at":"2023-09-06T08:24:16.231Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"https://flyt.robinthomas2591.now.sh/","language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/robin-thomas.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2019-10-15T22:28:57.000Z","updated_at":"2023-09-06T07:00:52.000Z","dependencies_parsed_at":"2022-08-25T12:41:39.431Z","dependency_job_id":null,"html_url":"https://github.com/robin-thomas/flyt","commit_stats":null,"previous_names":[],"tags_count":0,"template":null,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/robin-thomas%2Fflyt","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/robin-thomas%2Fflyt/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/robin-thomas%2Fflyt/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/robin-thomas%2Fflyt/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/robin-thomas","download_url":"https://codeload.github.com/robin-thomas/flyt/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244623563,"owners_count":20483174,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-03-20T13:57:21.806Z","updated_at":"2025-03-20T13:57:23.105Z","avatar_url":"https://github.com/robin-thomas.png","language":"JavaScript","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Flyt\n![](https://img.shields.io/badge/nodejs-12.04-blue.svg)\n![](https://img.shields.io/badge/solidity-0.5.8-red)\n[![License](https://img.shields.io/badge/license-MIT-green.svg)](https://opensource.org/licenses/MIT)\n\n## [Winner of CoinList + Chainlink hackathon!!](https://blog.chain.link/winners-of-the-chainlink-virtual-hackathon/)\n\n**Demo:** https://flyt.robinthomas2591.now.sh/\n\n**Swagger docs for APIs:** https://flyt.robinthomas2591.now.sh/swagger\n\n# Table of Contents\n1. [Introduction](#introduction)\n2. [Features](#features)\n3. [Architecture](#architecture)\n    - [Frontend](#frontend)\n    - [Backend](#backend)\n    - [Blockchain](#blockchain)\n4. [Tests](#tests)\n    - [API Tests](#api-tests)\n    - [Smart Contract Tests](#smart-contract-tests)\n5. [Installation](#installation)\n\n# Introduction\n**Flyt** is a Flight Insurance dapp running on Ropsten ethereum testnet.\n\nWe have no concept of insurance claims thanks to our blockchain technology. Every eligible policies will be paid out within 24 hours of your flight arrival time. Never do you have to worry about flight insurance again!\n\n# Features\n* No accounts or personal details required\n* Search for flights based on departure \u0026 arrival airport and date\n* Fully customizable policy. Can add or remove policy products for which you want to be insured against\n* Pay the insurance premium in ETH or a multitude of other cryptocurrencies, thanks to Kyber's technology\n* Download the insurance policy document in PDF form\n* Search for a policy if you know the policy ID\n* Policy shall be paid automatically in ETH to the same wallet from which the premium was paid, once it matures and the user is eligible for a payout.\n* Nothing for the user to do other than buying a policy!\n\n# Architecture\n\n### Frontend\nThe front-end code is written using React, CSS and HTML.\n\nThe UI is designed in the form of a stepper form. Once the user selects the departure and arrival airport and departure date, a selection of flights satisfying those criterias will be displayed, from which one should be selected. The user also has the option to add items for which he/she needs to be insured for.\n\nNext is the payment page. The premium the user needs to pay is based on the amount of risk for that policy. The risk is calculated from:\n- 70% weightage = past performance of that flight (any cancellations, flight delayed for 15, 30, 45 minutes and so on).\n- 30% weightage = departure airport delays (any cancellations, flights delayed for 15, 30, 45 minutes and so on)\nIf the risk is high, the premium to be paid will also be higher.\n\nThe premium calculation is done thanks to Chainlink and smart contracts (which is explained in the blockchain section).\n\n### Backend\nBackend is an express server for handling API requests and for payment callbacks (from Kyber).\n\nAll flight related APIs are routed through our backend, as the API key \u0026 secrets are not stored in this github repo (but rather in our server). Likewise, the private keys of our ethereum account.\n\nThe server also uses a key-value cache to speed up some calculations and performance improvements.\n\n#### Calculating the Policy maturity payment:\nThe policy maturity payment is calculated based on the delay, cancellation of the flight and the insurance products againt which the user has insured for.\n\n*Max possible payment is set to the cancellation rate (which is 1 ETH).*\n\nOnce the total delay (including the departure and arrival) is calculated, then the total payment is calculated by the following stub:\n- first 15 minutes delay are paid at a rate of 0.001 ETH per minute\n- next 30 minutes are paid at a rate of 0.002 ETH per minute\n- next 60 minutes are paid at a rate of 0.003 ETH per minute\n- next 120 minutes are paid at a rate of 0.004 ETH per minute\n\n### Blockchain\nOur smart contract (Flyt.sol) is deployed to Ropsten ethereum testnet.\n\nWhen a request comes in to calculate the premium for a policy, it'll create 2 Chainlink requests to be sent to the Oracle - once to calculate the aiport rating and the other to calculate the flight rating. When any of the jobs are completed, it'll **update the state of the Premium object for that policy**. Then (thanks to safemath operations), we use **weighted average** method to calculate the premium risk.\n\nThis is then passed to the backend server.\n\n# Tests\nTests are categorised into:\n- API tests\n- Smart contract tests\n\n### API Tests\nAPI tests are run by spawning a local instance of the *express* server that will then connect to the Ropsten ethereum test network before running the tests. These tests are written using *mocha* and *chai*. Test coverage is from *nyc*.\n\nSince the private key of the ethereum wallet is not shared in this github repo, only pure/view contract functions can be executed by these API functional tests. As such, all other contract functions are not covered by these tests.\n\n```sh\n$ npm run dapp:api:test\n$ npm run dapp:api:coverage\n```\n\n### Smart Contract Tests\nSmart Contract tests are written using *mocha* and are executed with the help of *truffle*. Test coverage is from *solidity-coverage*.\n\nThese tests cover both pure/view and stateful smart contract functions and have almost full coverage of the Flyt contract (barring the section of code that is used to set Chainlink public network details).\n\nThese tests are run in a test *ganache* network, which mocks the Chainlink network (by creating a LINK token, an ORACLE contract and using those with the Flyt contract). The LINK token is used for making Chainlink requests. Fulfillment function of the oracle is mocked based on the chainlink request to be made.\n\n```sh\n$ npm run contract:test\n$ npm run contract:coverage\n```\n\n# Deployment\nDeployment of **flyt** has two parts:\n- Deployment of flyt smart contracts\n- Deployment of flyt dapp\n\nThere is also a command to deploy both smart contracts \u0026 dapp together:\n\n```sh\n$ npm run deploy\n```\n\n### Deployment of flyt smart contracts\nFlyt smart contracts can be deployed to **Ropsten** ethereum testnet, by running the below command:\n\n```sh\n$ npm run contract:deploy\n```\n\nCompiled versions of the smart contracts will be stored in `src/truffle/_build/contracts`.\n\n### Deployment of flyt dapp\nAs explained above, flyt dapp has two parts - frontend \u0026 backend. Currently its using free [Now](https://zeit.co/) hosting for both. All you need to do is to create a Now account, and then run the below command.\n\n```sh\n$ npm run dapp:deploy\n```\n\nMake sure you create a file called **keys.json** in `/src` directory before deploying the dapp. It follows the below structure.\n```json\n{\n  \"infura\": {\n    \"ropsten\": {\n      \"api\": \"https://ropsten.infura.io/v3/\u003cinfura key\u003e\",\n      \"key\": \"\u003cinfura key\u003e\"\n    }\n  },\n  \"metamask\": {\n    \"mnemonic\": \"\u003cmetamask mnemonic of your ethereum wallet\u003e\"\n  },\n  \"flightstats\": {\n    \"appId\": \"\u003cflightstats appId\u003e\",\n    \"appKey\": \"\u003cflightstats appKey\u003e\"\n  }\n}\n```\n\nTo get `\u003cinfura key\u003e`, create an account here: https://infura.io/dashboard\n\nTo get `\u003cflightstats appId\u003e` \u0026 `\u003cflightstats appKey\u003e`, create an account here: https://developer.flightstats.com/products\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frobin-thomas%2Fflyt","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Frobin-thomas%2Fflyt","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Frobin-thomas%2Fflyt/lists"}