Giter Site home page Giter Site logo

blockful-io / swaplace-subgraph Goto Github PK

View Code? Open in Web Editor NEW
3.0 0.0 4.0 298 KB

Swaplace is an open-source, ownerless and feeless token swap protocol

Home Page: https://app.swaplace.xyz/

License: MIT License

TypeScript 100.00%
abi json solidity subgraph thegraphprotocol typescript

swaplace-subgraph's Introduction

swaplace-subgraph

Pre requisites:

Install Graph cli using NPM

NPM

$ npm install -g @graphprotocol/graph-cli

Docker Desktop

nodeJS LTS

Install dependencies

npm i

Setting Up Local Blockchain

Run a Hardhat node:

npx hardhat node

NOTE: Note: Use the first account to avoid errors.

Deploying Smart Contracts to Local Blockchain

Deploy the Swaplace contract

npx hardhat run --network localhost scripts/deploy.ts

Install subgraph dependencies

cd /swaplace-subgraph/
npm i

Running docker

Go to the graph-node directory

cd swaplace-subgraph/graph-node

Make sure there is not any residual file remaining in the directory

rm -rf graph-node/data/

start the docker

docker-compose up

You should see the log looking like this for the docker:

    *graph-node-graph-node-1  |* Oct 15 04:44:57.420 INFO Downloading latest blocks from Ethereum, this may take a few minutes..., provider: localhost-rpc-0, component: EthereumPollingBlockIngestor

And looking something like this for hardhat:

    eth_blockNumber (2)
    eth_getBlockByNumber (19)
    eth_blockNumber (2)
    eth_getBlockByNumber (14)

Create a subgraph

cd swaplace-subgraph
graph create --node http://localhost:8020/ subgraph/swaplace

Deploy the subgraph

graph deploy --node http://localhost:8020/ --ipfs http://localhost:5001 subgraph/swaplace

The Graph Explorer

Run the test scripts on the local network to generate events to check on The Graph Explorer with queries. Example of query:

query MyQuery {

swapCreateds(first: 2) { creator id Swaplace_id blockNumber } }

In case you update the smart contract with new events to be added

  1. Cancel and clean the docker. In the graph-node folder running the docker, press crtl + c and type docker-compose down, then delete the data folder rm -rf /data
  2. Update the smart contract and compile it
  3. Update the files swaplace-subgraph/networks.json and the swaplace-subgraph/subgraph.yaml with the new address
  4. Copy and paste the new ABI on swaplace-subgraph/abis/Swaplace.json
  5. Update the file swaplace-subgraph/schema.graphql with the new entities
  6. Update the file swaplace-subgraph/subgraph.ymal with the new event handlers
  7. Update the file swaplace-subgraph/src/swaplace.ts with the new functions and imports
  8. Run the commands graph codegen and graph build --network localhost in the swaplace-subgraph folder.
  9. Deploy the new version of the subgraph graph deploy --node http://localhost:8020/ --ipfs http://localhost:5001 subgraph/swaplace

Tesnet and Mainnet

  1. Access the studio https://thegraph.com/studio/, connect your wallet and create a subgraph
  2. Give a name and select a network
  3. Run the command line: graph init --studio <your subgraph name>
  4. Choose the protocol you want to deploy the subgraph
  5. Create the slug which will be the unique identifier your subgraph will be identified by
  6. Create the name of the directory that will have the subgraph files
  7. Choose the network you want to deploy the subgraph
  8. Fill the address field with the smart contract deployed on the network
  9. Set the path to the ABI file
  10. Fill the block in which the contract was deployed to
  11. Give the name of the contract
  12. Press "Y" to index events as entities
  13. Press "n" if you don't want to add another contract.
  14. Run the command graph auth --studio <your subgraph deploy key>
  15. Go to the subgraph's directory cd swaplace-subgraph
  16. Run the commands graph codegen && graph build to generate the necessary files
  17. Run the command graph deploy --studio swaplace-subgraph to deploy the subgraph

Use The Graph Studio to play around with the queries. You can use the query mentioned earlier to start.

swaplace-subgraph's People

Contributors

0xneves avatar rafadsan avatar

Stargazers

 avatar  avatar  avatar

swaplace-subgraph's Issues

feat: Minimizing downtime of Ponder application on RailWay side

Feature Request

Describe the Feature Request

As we are approaching the production environment we should prioritize the maximum uptime of the application as possible once the migration (issue 34) is completed.

Describe Preferred Solution

Not Working

  • Configure the RailWay platform to make an instant reboot in the server once it has stopped
  • Create redundancy with new instances so that the fetching process can be made for an instance that is working in case one is down

Zero Downtime Redeployments

  • only route requests to a new instance once it is healthy and ready to handle requests.

feat:Update Ponder to be up to date with Swaplace contract

Feature Request

Updated ABI the latest version
Update ponder.config.ts with latest address
Update ponder.schema.ts to correct allowed type and status
Added new functions to update allowed properties

Describe the Feature Request

Describe Preferred Solution

Describe Alternatives

Related Code

Additional Context

feat: Subgraph to index swap offers

Feature Request

As our current backend indexer (Ponder) is not working properly with the kakarot network, we should try another alternative and check if it works. We suggest the subgraph protocol.

Describe Preferred Solution

  • Install the subgraph CLI in your local machine
  • Configure the subgraph in the swaplace-dapp repository to work with graph-node locally
  • Deploy the subgraph-swaplace to your local graph-node
  • Use the endpoint provided when the subgraph is deployed
  • Make a simple query to check if the returns are valid
  • Make the necessary tests to come to a conclusion

Create an issue on `swaplace-contracts` to update `hardhat.config.ts` for Subgraph usage

Feature Request

Describe the Feature Request

This update will require that most network configurations on hardhat.config.ts respect a pattern within the GitHub actions as well.

Definition of Done:

  • Make sure the hardhat configuration is working alongside the local Docker
  • Make sure the GitHub actions are being respected. There is an ongoing issue where we can only test the actions by submitting PRs directly to the official repository
  • Create an issue describing why this change needs to happen to the hardhat.config.ts

feat: rank users by their respective total points

Feature Request

Describe the Feature Request

Definition of done:

  • Create a query to fetch the data from the user (Rank, Address, Points)
  • Create a logic to retrieve getTotalPoints and the getAddressRank

Describe Preferred Solution

  • The backend will retrieve all the information we need to display the rank in frontend.
  • It's necessary get the rank in backend to display the current rank from the respective user.

Related Code

ProfileDatabases

feat: Separate events by network

Feature Request

As we added a new network to the Swaplace App, kakarot_sepolia we should separate the events emitted by the smart contract by networks, otherwise, the events would be all mixed up, making it troublesome to correctly display in the frontend.

Describe the Feature Request

  • Add a new property in ponder.schema.ts -> SwapDatabase regarding the networks.
  • In Swaplace.ts add this new property into the SwapDatabase objects and make it have the correct value to check in what network the event is coming from.

feat: kickstart subgraph repository for swaplace

The client must be installed and also an account must be registered within their API.

We'll be looking to implement the following as the Subgraph tasks develop:

  • Run local net
  • Run testnet
  • Run mainnet
  • Prepare README.md

feat: Scoreboard ranking divided by chain

Feature Request

Describe the Feature Request

Each different blockchain where Swaplace is deployed will have to have a specific scoreboard for them, so it's necessary to adjust the Swaplace.ts and ponder.schema.ts to accept this feature

Create a README.md on how to run Docker+Local Server

Feature Request

Describe the Feature Request

After altering so much about the current aspect of the repo we must update the README.md so other users can understand how to easily run the project we are proposing here.

Adapt the old readme, or create a new one containing the installation and versioning of the tools (node, docker, subgraph) used.

Definition of Done:

  • Create a brief introduction to what was build and what it serves for
  • Explain how to install the libs and their respectful versioning
  • Explain how to configure environment variables
  • Explain how to use the script commands
  • Explain any adverse condition or possible facing issues
  • Explain how to become a Contributor (Read swaplace-contracts or swaplace-dapp for inspiration)

feat: native ether in swap schema

Feature Request

Describe the Feature Request

There is a new contract upgrade incoming, and two new variables will be added to the config. It's them: The recipient and the value.

  • Recipient: Is a value between 0 and 255. It will define which part of the swap is receiving the Ether. '0' means that the acceptee (caller of acceptSwap()) will receive the ether while any values above '0' (1~255) means the receiver is the swap creator (caller of creatSwap()).

  • Value: this is the ether amount to be sent in the swap. We must compress this value to give it more space for other blockchains.

Explaining compression:

  • uint56 is equals 72,057,594,037,927,935.
  • decimals in blockchains uses 18 decimals.
  • using uint56 would result in sending a maximum value of 0.072057594.... ethers. Which is worth in dollars around $252. But when applied to other currencies such as $MATIC it would become $0,08.

We cannot have a trading dApp with such small amount of values. But we also cannot supress our gas limit.

The solution is pretty simple:

  • we assume that all values that are smaller than $0,01 are not worth using to equilibrate the swap value. Why would you send someone 0,0000000005 ethers in a trade? It's worthless, specially for other blockchains.
  • hence the compression. We are going to remove the last 12 decimal houses from the value to allow for a better description of the 17 decimals that we can use as a prefix.
  • by multiplying on-chain our value by a factor of 12, we can increase 12 decimals houses of the 0 value, resulting in an increase of the maximum value to 72,057,594,037.927935000000000000 which is more than any blockchain maximum supply.
  • while setting the minimum possible value for ethereum transfer into 0.000001, which is roughly $0,0035. (6 decimal houses)
  • the last 12 decimal houses will always be '0'.

How this affects the creation of swaps?

  • when creating a swap you should always divide your msg.value (ether to be sent) by 12.
  • if you are sending 0,0123 ethers then instead of using:
    "12300000000000000" as a parameter for the "value" when encoding the 'config', you should actualy use "12300", because the smart contract will add the other decimals for you:
    if (value > 0 && recipient == 0) {
      if (value * 1e12 != msg.value) revert InvalidValue();
    }

Describe Preferred Solution

Definition of Done:

  • Add more two variables into the swap schema: recipient and value, both as bigint.
  • update the decode function after casting getSwap() because we must decode with the recipient and the value as well (previously only allowed and expiry)

Related Code

Function to encode the parameters with the native ether

Run subgraph locally in Docker

Feature Request

Describe the Feature Request

Start coding in the develop branch.

Definition of Done:

  • Remove the unnecessary files from the current repository which is setting up the Subgraph directly in the official Subgraph Studio
  • Add all features to run the Docker
  • Add the necessary files for running Subgraph locally
  • Configure to communicate with hardhat ( check #13 )
  • Make sure the Docker is running correctly and that it will resume activity or reset the jobs in case the Subgraph stops working ( configure Docker for great uptime )

fix: workflow do not belong to this repo

Bug Report

Current behavior

Github actions is trying to run a workflow that do not exist in this repository

Expected behavior

No workflows running for now

Steps to reproduce

Commit anything or open PRs

Related code

This directory

feat: Express-server running

Feature Request

Describe the Feature Request

The current protocol Swaplace is using to configure its backend and index events is the Ponder application, but this technology is not mature enough to, therefore we are limited to the Ponder's limited features meanwhile we could communicate directly with our own database, with no third-parties.

Hence, we are aiming to change it slowly, starting with deploying an express server to the railway cloud, configured to work with the current PostgreSQL.

Describe Preferred Solution

  • Install express.
  • config express to communicate with our deployed PostgresSQL.
  • Deploy the express server to the railway platform.

feat: React Query Migration

Feature Request

Migrate the current Axios library for React Query library

Describe the Feature Request

Replace the Axios lib with React Query lib due to the following reasons:

  1. Built-in caching and automatic refetching help optimize API calls and reduce unnecessary requests.
  2. Provides a more declarative approach to data fetching and management.
  3. Integrates well with TypeScript and has good type definitions.
  4. The complexity level is increasing with the addition of the pagination feature, which the React Query will better fit with this feature.

Describe Preferred Solution

The query should be fetched correctly, with no errors,
Less unnecessary requests,
Cursor Pagination working,

Point subgraph requests to Sepolia Testnet

Feature Request

Describe the Feature Request

The local subgraph is standardized to run on the local net like the hardhat node option at localhost:3030. But we need to point our local Subgraph into the network of our choice by providing three arguments: The chain id, the RPC URL and the smart contract address.

Definition of Done:

  • Update the networks.json in the Subgraph core config files
  • Update subgraph.yml to work specifically with a target network
  • Add Sepolia in the .env as the target test cases.

feat: Migration of Ponder Homolgation Endpoint to Swaplace Production Endpoint

Feature Request

Describe the Feature Request

So far the Swaplace is using a temporary homologation endpoint to fetch the ponder's application data (https://rascar-swaplace-ponder-production.up.railway.app/) which is serving for tests before it's deployed into an official Swaplace endpoint.
As we are approaching a stable version of Ponder, we should start the process of migration.

Describe Preferred Solution

Definition of Done:

  • Test ponder locally, it should not present any critical errors that stop the application from running,
  • Test ponder in the homologation endpoint, it should not present any critical errors that stop the application from running,
  • Configure the healthcheck of the endpoint to make sure it's correctly running and deployed
  • Share the new endpoint URL with the DEVs

feat: Migrate current ponder application to subgraph + backend

Feature Request

Describe the Feature Request

Currently Swaplace is using the Ponder application (this repo) and Potsgress database through the Railway platform to index and store the events data emitted by the smart contract. However, this stack is not addressing all the Swaplace scope, therefore it will be necessary to change to the The Graph indexer as it is more consolidated, and set up a Swaplace's database.

feat: Expiry returning as unixTimeStamp

Feature Request

Describe the Feature Request

Make the expiry from the config return a unixTimeStamp value so it can correctly work with the queries in the frontend.

fix: `client.getEnsName` not fetching Ens Data

Bug Report

Ponder version

0.3.10

Current behavior

We are using Viem through Ponder to make the communication with the Swaplace Smart Contract deployed on Sepolia to fetch Ens information about a user, but whenever the function is called, it always returns the same error Error resolving ENS for address AnyAddressHere: TypeError: Cannot read properties of undefined (reading 'toLowerCase').

Expected behavior

When running the script npm run dev the ponder should execute and do not bring any errors for address that are corrected passed.

Steps to reproduce

Run the command npm run dev as it's in the ponder branch, it will show the error previously presented.

Related code

export async function getEnsData(client: any, address: any) {
  try {
    const primaryName = await client.getEnsName(address);
    return primaryName;
  } catch (error) {
    console.error(`Error resolving ENS for address ${address}:`, error);
    throw error;
  }
}

Other information

Despite what the error is implying, the parameter being passed to the function is a correct address, an owner parameter that is also passed in other functions inside the same scope, and it works fine, meaning that the client.getEnsName(address); might be the problem.

In communication with the Ponder team, they've told us that they've realized a fix for the problem in version 0.3.10, but it could still be holding the error, so it needs further investigation.

We suggest working with the Ponder team to fix this error.

Ponder Telegram -> https://t.me/ponder_sh

Related code

getEns.ts
Swaplace.ts

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.