Git Product home page Git Product logo

storypoints's Introduction

Origin Story Points System

This is a simple story points system for the Origin Story marketplace. It awards points to wallets based on activities performed. The system comprises 3 parts:

There is a single data entity (model) in the system called Activity. An activity is a record of some activity performed by some wallet, optionally on some contract address, with some set of points awarded. The points awarded are determined by the type of activity. The system is designed to be extensible, so new event types can be added easily.

  • packages/api - a very simple API gives leaderboard stats based on aggregations on the Event model
  • packages/infra - CDK devops infrastructure stuff
  • packages/ingest - Data ingestion logic
  • packages/models - Sequelize model for the Event entity
  • packages/rules - Points calculations rules and loaders
  • packages/utils - Various minor standalone utilities used across packages

The API server is a very simple Node Express JS server. It serves the Open API specs defined at https://app.swaggerhub.com/apis-docs/edspencer/Points/1.0.11#/Leaderboards/getLeaders.

Running the system locally

To run the system locally, you need to have Node JS installed. You also need to have a postgres database running.

You can configure the database and permissions with these queries:

CREATE DATABASE storypoints;
CREATE USER storypoints;
GRANT ALL ON DATABASE storypoints TO storypoints;
GRANT ALL ON SCHEMA public TO storypoints;

To run migrations:

yarn migrate

To run the Node JS API:

yarn start

Running the tests:

yarn test

Commands

API Calls

Add a collection:

curl -v -X POST -H 'Content-Type: application/json' --data '{"contractAddress": "0x3bf2922f4520a8ba0c2efc3d2a1539678dad5e9d", "description": ""}' http://localhost:3000/collection

Trigger a fetch (local):

curl -v -X POST -H 'Content-Type: application/json' --data '{"contractAddresses": ["0x3bf2922f4520a8ba0c2efc3d2a1539678dad5e9d"], "full": true, "requestLimit": 500}' http://localhost:3000/work

Trigger a fetch (remote):

curl -v -X POST -H 'Content-Type: application/json' --data '{"contractAddresses": ["0x3bf2922f4520a8ba0c2efc3d2a1539678dad5e9d"], "full": true, "requestLimit": 500}' http://LBENDPOINT.us-east-2.elb.amazonaws.com/trigger

storypoints's People

Contributors

edspencer avatar mikeshultz avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

storypoints's Issues

Health endpoint showing lag

Getting some alerts where the /health endpoint is

{
  "diff": 3840,
  "healthy": false,
  "latest": 1687297790,
  "latestHuman": "2023-06-20T21:49:50.000Z",
  "reservoir": 1687301630,
  "reservoirHuman": "2023-06-20T22:53:50.000Z",
}

Since /health uses the same endpoint as ingestion, this implies that ingestion is behind what the endpoint is returning by 64 minutes.

Multiple sales in a single tx are seen as duplicate

Seems like multiple sales in a single tx are being seen as duplicates when they're individual activities. For instance, these two activities:

[
    {
      "type": "sale",
      "fromAddress": "0x5d4ba8099edd5538d8c91fbc285271f012275b19",
      "toAddress": "0x2c6b8c19dd7174f6e0cc56424210f19eefe62f94",
      "price": {
        "currency": {
          "contract": "0x0000000000000000000000000000000000000000",
          "name": "Matic Token",
          "symbol": "MATIC",
          "decimals": 18
        },
        "amount": {
          "raw": "4200000000000000000",
          "decimal": 4.2,
          "usd": 3.67444,
          "native": 4.2
        }
      },
      "amount": 1,
      "timestamp": 1685032019,
      "createdAt": "2023-05-25T16:27:01.580Z",
      "contract": "0xf37c1a9c39d2e8f29d4bb74b999ebf6bb9c14bb9",
      "token": {
        "tokenId": "213",
        "tokenImage": "https://lh3.googleusercontent.com/f0njNLYht2SwLMWKsgO0LYHZkxxkLmMZH98uo8Rvb9IeMS0T7Ne-iSDXa00soqyO_yqFqo0bUm_2zxlfpxtvKlilmWPkzIz3bU8",
        "tokenName": "DUCK SEASON #213",
        "lastBuy": {
          "value": 2.11372,
          "timestamp": 1678795888
        },
        "lastSell": {
          "value": 4.2,
          "timestamp": 1685032019
        },
        "tokenRarityRank": 1079,
        "tokenRarityScore": 45.567,
        "tokenMedia": null
      },
      "collection": {
        "collectionId": "0xf37c1a9c39d2e8f29d4bb74b999ebf6bb9c14bb9",
        "collectionImage": "https://i.seadn.io/gcs/files/50e0aafc5736a3d48657ffb4f34d89d4.gif?w=500&auto=format",
        "collectionName": "Duck-Season"
      },
      "txHash": "0xc8497744367f20b6f2272cf1aeaa5e639db0d12d51937026a60988addbe55762",
      "logIndex": 341,
      "batchIndex": 1,
      "order": {
        "id": "0x6adede3f842dc70714c9d2c248244bfb3b517e984a6ff4a8a6ad3b04a31d8f22",
        "side": "ask",
        "source": {
          "domain": "story.xyz",
          "name": "story.xyz",
          "icon": "https://story.xyz/favicon.ico"
        },
        "criteria": {
          "kind": "token",
          "data": {
            "token": {
              "tokenId": "213",
              "name": "DUCK SEASON #213",
              "image": "https://lh3.googleusercontent.com/f0njNLYht2SwLMWKsgO0LYHZkxxkLmMZH98uo8Rvb9IeMS0T7Ne-iSDXa00soqyO_yqFqo0bUm_2zxlfpxtvKlilmWPkzIz3bU8"
            },
            "collection": {
              "id": "0xf37c1a9c39d2e8f29d4bb74b999ebf6bb9c14bb9",
              "name": "Duck-Season",
              "image": "https://i.seadn.io/gcs/files/50e0aafc5736a3d48657ffb4f34d89d4.gif?w=500&auto=format"
            }
          }
        }
      }
    },
    {
      "type": "sale",
      "fromAddress": "0x5d4ba8099edd5538d8c91fbc285271f012275b19",
      "toAddress": "0x2c6b8c19dd7174f6e0cc56424210f19eefe62f94",
      "price": {
        "currency": {
          "contract": "0x0000000000000000000000000000000000000000",
          "name": "Matic Token",
          "symbol": "MATIC",
          "decimals": 18
        },
        "amount": {
          "raw": "4200000000000000000",
          "decimal": 4.2,
          "usd": 3.67444,
          "native": 4.2
        }
      },
      "amount": 1,
      "timestamp": 1685032019,
      "createdAt": "2023-05-25T16:27:01.580Z",
      "contract": "0xf37c1a9c39d2e8f29d4bb74b999ebf6bb9c14bb9",
      "token": {
        "tokenId": "1388",
        "tokenImage": "https://lh3.googleusercontent.com/QpBJ1DxlsSl-kLs1kKr3IChFUllUUFKZHDCcBlDw_3eNjql8VaMpRAqGvocdHbXSW9FuQyRQXL32IiijLBD1ivo8hHXwfjg2ng4",
        "tokenName": "DUCK SEASON #1388",
        "lastSell": {
          "value": 4.2,
          "timestamp": 1685032019
        },
        "tokenRarityRank": 747,
        "tokenRarityScore": 51.881,
        "tokenMedia": null
      },
      "collection": {
        "collectionId": "0xf37c1a9c39d2e8f29d4bb74b999ebf6bb9c14bb9",
        "collectionImage": "https://i.seadn.io/gcs/files/50e0aafc5736a3d48657ffb4f34d89d4.gif?w=500&auto=format",
        "collectionName": "Duck-Season"
      },
      "txHash": "0xc8497744367f20b6f2272cf1aeaa5e639db0d12d51937026a60988addbe55762",
      "logIndex": 342,
      "batchIndex": 1,
      "order": {
        "id": "0x06342e6aec410871c9ebc911248cb46700b4fcdadcc58ed109ec98dcae0d64bf",
        "side": "ask",
        "source": {
          "domain": "story.xyz",
          "name": "story.xyz",
          "icon": "https://story.xyz/favicon.ico"
        },
        "criteria": {
          "kind": "token",
          "data": {
            "token": {
              "tokenId": "1388",
              "name": "DUCK SEASON #1388",
              "image": "https://lh3.googleusercontent.com/QpBJ1DxlsSl-kLs1kKr3IChFUllUUFKZHDCcBlDw_3eNjql8VaMpRAqGvocdHbXSW9FuQyRQXL32IiijLBD1ivo8hHXwfjg2ng4"
            },
            "collection": {
              "id": "0xf37c1a9c39d2e8f29d4bb74b999ebf6bb9c14bb9",
              "name": "Duck-Season",
              "image": "https://i.seadn.io/gcs/files/50e0aafc5736a3d48657ffb4f34d89d4.gif?w=500&auto=format"
            }
          }
        }
      }
    }
]

Since the hashing function only includes type, address, collection, and timestamp, anything occuring within the same tx would collide.

export function hashActivity(act: IActivity) {
// TODO: Should validate these are the best choice of props for uniqueness
const hashValues = [
act.type,
act.walletAddress ? buf2hex(act.walletAddress) : '',
buf2hex(act.contractAddress),
+act.timestamp,
]
return hex2buf(sha256(hashValues.join('-')))
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.