GithubHelp home page GithubHelp logo

marginswap-subgraph's Introduction

Marginswap Subgraph

Deployed on legacy explorer

Polygon

https://thegraph.com/legacy-explorer/subgraph/marginswap/marginswap-v1-polygon

BSC

https://thegraph.com/legacy-explorer/subgraph/marginswap/marginswap-v1-bsc

Avalanche

https://thegraph.com/legacy-explorer/subgraph/marginswap/marginswap-v1-avalanche

Running Locally

  • Clone Graph Node git clone https://github.com/graphprotocol/graph-node/
  • Enter the Graph Node's Docker directory: cd graph-node/docker
  • Linux users need to run: ./setup.sh
  • docker-compose up -d
    • If this fails with a Mounts Denied error on mac, in docker desktop, go to Preferences > Resources > File Sharing and add the graph's docker directory as an allowed directory
  • Make your edits to the subgraph code
  • Create the subgraph locally: yarn create-local
  • Run codegen yarn codegen
  • Build the code yarn build
  • Deploy the subgraph locally: yarn deploy-local
  • Visit http://localhost:8000/subgraphs/name/marginswap/marginswap-subgraph/graphql

Logs

There are two options for getting logs:

  1. For basic logs, click on Docker Desktop > docker > docker_graph_node_1
  2. For more detailed, debug logs, run sudo docker ps -a then get the ID for the graph-node container, and then run sudo docker logs -f <project-id>

Local Chain

  • For local dev, this will talk to the local chain from the marginswap-core hardhat script. However, you'll need to swap out the infura URL in the hardhat config for an Alchemy one so you get the full archive node. Archive nodes are required for making contract method calls like we do in the margin-router event event handler.

Deploying

  • Run the deploy script for the network you want to deploy on. yarn prepare:bsc, yarn prepare:mainnet, yarn prepare:avalanche, or yarn prepare:polygon
  • Manually update the contract address in /src/mappings/margin-router.ts to the correct address for the CrossMarginTrading contract on the network you are deploying to. Get the address from the marginswap-core repo in /build/addresses.json
  • Authenticate: graph auth --product hosted-service <ACCESS_TOKEN> (get access token from another dev or from thegraph.com URL below)
  • Deploy: graph deploy --product hosted-service marginswap/marginswap-v1-<network>
  • In the browser, navigate to https://thegraph.com/legacy-explorer/subgraph/marginswap/marginswap-v1-<network> where <network> is either bsc, polygon, or mainnet

marginswap-subgraph's People

Contributors

aloaiza-dev avatar jordajm avatar werg avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

levintech

marginswap-subgraph's Issues

Cumulative Incentive claims

We want to compute how much MFI incentive a user gets. The addToClaim and subtractFromClaim events are our basis for this calculation. For now we want to retrieve for every user, for every token they hold, the cumulative claim that they have.

Ultimately we will need to accumulate the claim balance in the following manner:

  • we have variables ongoingClaim and cumulativeClaimBalance, starting at 0, as well as lastUpdatedTimestamp
  • for either event compute the cumulativeClaimBalance += ongoingClaim * (currentTime - lastUpdatedTimestamp)
  • if it's an addToClaim we add the amount to ongoingClaim
  • otherwise we subtract

In my understanding there possibly are two ways to do this:

  • we make our graphql mapping very simple, basically just forwarding the event and then we do the agglomerative math in post-query logic
  • we integrate this into the mapping and present a claim-per-token entity to the client

Other queries / entities

We want all of the below values per individual token as well as in total converted to USD

  • Total lending
  • Total value held in crossmargin
  • Total value locked: max of total value in lending and cross margin accounts
  • Daily trading volume: sum of all trades per day or for the last 24 hours
  • Also if possible each individual swaps for exchange trackers like coinmarketcap and coingecko (ask dr o)
  • Lending interest rate
  • Borrowing interest rate

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.