Skip to content
This repository has been archived by the owner on Mar 22, 2023. It is now read-only.

Commit

Permalink
minor changes , readme added
Browse files Browse the repository at this point in the history
  • Loading branch information
Hammad-Mubeen committed Nov 9, 2021
1 parent 89d7b9a commit f1f4511
Show file tree
Hide file tree
Showing 7 changed files with 74 additions and 121 deletions.
17 changes: 6 additions & 11 deletions .env
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
NODE_MODE=developement
NODE_MODE=deployed
DATABASE_URL_LOCAL=mongodb://localhost:27017/V2-graphQL
DATABASE_URL_ONLINE=mongodb+srv://admin:[email protected]/V2-graphQL?retryWrites=true&w=majority
FACTORY_ADDRESS=157ece984b5ee7c58ae95299b4b7afa890bddb1d9f710fe2384a9e589f9b1bb8
token0=ebd3469763c597ef971782ea6a164531183c2251cac023cabf84b7c6bb521136
token1=d595a82535e34b87ee37b5cc094241304e28b0904f70ff83ffbc9f71bc9b5410
pair=5d7922b0281a1074663be274d0e0e8bd14aae748aa28d3b552aef8d0a5a7963b
FACTORY_CONTRACT=157ece984b5ee7c58ae95299b4b7afa890bddb1d9f710fe2384a9e589f9b1bb8
PAIR_CONTRACT=5d7922b0281a1074663be274d0e0e8bd14aae748aa28d3b552aef8d0a5a7963b
CALLEE_CONTRACT=fbfeda8b97f056f526f20c2fc2b486d9bdbfb3e46b9a164527e57c0c86e68612
TOKEN0_CONTRACT=ebd3469763c597ef971782ea6a164531183c2251cac023cabf84b7c6bb521136
TOKEN1_CONTRACT=d595a82535e34b87ee37b5cc094241304e28b0904f70ff83ffbc9f71bc9b5410

GRAPHQL=http://localhost:3000/graphql
CHAIN_NAME=casper-test
Expand Down Expand Up @@ -67,9 +68,3 @@ SET_TREASURY_FEE_PERCENT_PAYMENT_AMOUNT=5000000000
SET_FEE_TO_PAYMENT_AMOUNT=5000000000
SET_FEE_TO_SETTER_PAYMENT_AMOUNT=5000000000
CREATE_PAIR_PAYMENT_AMOUNT=5000000000

FACTORY_CONTRACT=157ece984b5ee7c58ae95299b4b7afa890bddb1d9f710fe2384a9e589f9b1bb8
PAIR_CONTRACT=5d7922b0281a1074663be274d0e0e8bd14aae748aa28d3b552aef8d0a5a7963b
CALLEE_CONTRACT=fbfeda8b97f056f526f20c2fc2b486d9bdbfb3e46b9a164527e57c0c86e68612
TOKEN0_CONTRACT=ebd3469763c597ef971782ea6a164531183c2251cac023cabf84b7c6bb521136
TOKEN1_CONTRACT=d595a82535e34b87ee37b5cc094241304e28b0904f70ff83ffbc9f71bc9b5410
2 changes: 1 addition & 1 deletion graphql/dayUpdates.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ async function updateUniswapDayData (timeStamp) {

try {
let uniswap = await UniswapFactory.findOne({
id: process.env.FACTORY_ADDRESS,
id: process.env.FACTORY_CONTRACT,
});

let timestamp = timeStamp;
Expand Down
14 changes: 7 additions & 7 deletions graphql/mutations.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,11 @@ const handleNewPair = {

// load factory (create if first exchange)
let factory = await UniswapFactory.findOne({
id: process.env.FACTORY_ADDRESS,
id: process.env.FACTORY_CONTRACT,
});
if (factory === null) {
factory = new UniswapFactory({
id: process.env.FACTORY_ADDRESS,
id: process.env.FACTORY_CONTRACT,
pairCount: 0,
totalVolumeETH: ZERO_BD,
totalLiquidityETH: ZERO_BD,
Expand Down Expand Up @@ -239,7 +239,7 @@ const handleTransfer = {
}

let factory = await UniswapFactory.findOne({
id: process.env.FACTORY_ADDRESS,
id: process.env.FACTORY_CONTRACT,
});

let transactionHash = args.deployHash;
Expand Down Expand Up @@ -449,7 +449,7 @@ const handleSync = {
let token0 = await Token.findOne({ id: pair.token0 });
let token1 = await Token.findOne({ id: pair.token1 });
let uniswap = await UniswapFactory.findOne({
id: process.env.FACTORY_ADDRESS,
id: process.env.FACTORY_CONTRACT,
});

// reset factory liquidity by subtracting onluy tarcked liquidity
Expand Down Expand Up @@ -565,7 +565,7 @@ const handleMint = {

let pair = await Pair.findOne({ id: args.pairAddress });
let uniswap = await UniswapFactory.findOne({
id: process.env.FACTORY_ADDRESS,
id: process.env.FACTORY_CONTRACT,
});

let token0 = await Token.findOne({ id: pair.token0 });
Expand Down Expand Up @@ -672,7 +672,7 @@ const handleBurn = {

let pair = await Pair.findOne({ id: args.pairAaddress });
let uniswap = await UniswapFactory.findOne({
id: process.env.FACTORY_ADDRESS,
id: process.env.FACTORY_CONTRACT,
});

//update token info
Expand Down Expand Up @@ -828,7 +828,7 @@ const handleSwap = {

// update global values, only used tracked amounts for volume
let uniswap = await UniswapFactory.findOne({
id: process.env.FACTORY_ADDRESS,
id: process.env.FACTORY_CONTRACT,
});
uniswap.totalVolumeUSD = uniswap.totalVolumeUSD + trackedAmountUSD;
uniswap.totalVolumeETH = uniswap.totalVolumeETH + trackedAmountETH;
Expand Down
2 changes: 1 addition & 1 deletion graphql/pricing.js
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ async function findEthPerToken(token) {
}
// loop through whitelist and check if paired with any
for (let i = 0; i < WHITELIST.length; ++i) {
//let pairAddress = await factory.getPair(process.env.FACTORY_ADDRESS,token.id, WHITELIST[i]);
//let pairAddress = await factory.getPair(process.env.FACTORY_CONTRACT,token.id, WHITELIST[i]);

let pairAddress =
"hash-0000000000000000000000000000000000000000000000000000000000000000";
Expand Down
8 changes: 1 addition & 7 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,7 @@
"version": "0.0.0",
"private": true,
"scripts": {
"start": "ts-node ./bin/www",
"test:erc20install": "ts-node JsClients/ERC20/test/install.ts",
"test:erc20installed": "ts-node JsClients/ERC20/test/installed.ts",
"test:pairinstall": "ts-node JsClients/PAIR/test/install.ts",
"test:pairinstalled": "ts-node JsClients/PAIR/test/installed.ts",
"test:factoryinstall": "ts-node JsClients/FACTORY/test/install.ts",
"test:factoryinstalled": "ts-node JsClients/FACTORY/test/installed.ts"
"start": "ts-node ./bin/www"
},
"dependencies": {
"casper-js-sdk": "2.4.1",
Expand Down
58 changes: 58 additions & 0 deletions readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
# Casper_Uniswap_V2 GraphQL

Casper Uniswap is a decentralized protocol for automated token exchange on Casper.

This graphql dynamically tracks any pair created by the casper uniswap factory. It tracks of the current state of casper Uniswap contracts, and contains derived stats for things like historical data and USD prices.

- aggregated data across pairs and tokens,
- data on individual pairs and tokens,
- data on transactions
- data on liquidity providers
- historical data on Uniswap, pairs or tokens, aggregated by day

## Running Locally

npm install to install the require packages
npm start to start the server

## Queries

Below are a few ways to show how to query the casper-uniswap-graphql for data. The queries show most of the information that is queryable, but there are many other filtering options that can be used, just check out the [querying api](https://thegraph.com/docs/graphql-api). These queries can be used locally or in The Graph Explorer playground.

## Key Entity Overviews

#### Casper UniswapFactory

Contains data across all of Casper Uniswap V2. This entity tracks important things like total liquidity (in CSPR and USD, see below), all time volume, transaction count, number of pairs and more.

#### Token

Contains data on a specific token. This token specific data is aggregated across all pairs, and is updated whenever there is a transaction involving that token.

#### Pair

Contains data on a specific pair.

#### Transaction

Every transaction on Uniswap is stored. Each transaction contains an array of mints, burns, and swaps that occured within it.

#### Mint, Burn, Swap

These contain specifc information about a transaction. Things like which pair triggered the transaction, amounts, sender, recipient, and more. Each is linked to a parent Transaction entity.

## Example Queries

### Querying Aggregated Casper Uniswap Data

This query fetches aggredated data from all Casper uniswap pairs and tokens, to give a view into how much activity is happening within the whole protocol.

```graphql
{
uniswapFactories(first: 1) {
pairCount
totalVolumeUSD
totalLiquidityUSD
}
}
```
94 changes: 0 additions & 94 deletions test.js
Original file line number Diff line number Diff line change
@@ -1,94 +0,0 @@
// var mongoose = require('mongoose');
// require('mongoose-bigdecimal');
// var Schema = mongoose.Schema;
// var BigDecimal = require('big.js');

// //define your schema
// var ProductSchema = new Schema({
// price: {
// type: Schema.Types.BigDecimal,
// required: true,
// index:true
// },
// discounts:[{
// type: Schema.Types.BigDecimal
// }]
// });
// Product = mongoose.model('Product', ProductSchema);

// //use it
// var book = new Product();
// book.price = new BigDecimal(12);
// book.save(done);
// var data=[
// [
// { data: 'contract_package_hash' },
// {
// data: '0024dc4c2ea77a01a0da90893c3283cfa602d78acf198aaa67e61e9bc9b44c93'
// }
// ],
// [ { data: 'event_type' }, { data: 'transfer' } ],
// [
// { data: 'from' },
// {
// data: 'Key::Account(0000000000000000000000000000000000000000000000000000000000000000)'
// }
// ],
// [
// { data: 'to' },
// {
// data: 'Key::Account(e56a24ed039010d56c2f47aad13fb740b94f3253889500129421054ebb38d917)'
// }
// ],
// [ { data: 'value' }, { data: '50' } ]
// ];

// console.log("data: ",data[0][1].data);

const { request } = require('graphql-request');

// request('http://localhost:3000/graphql',
// `mutation handleTransfer( $pairAddress: String!, $from: String!, $to: String!, $value: Int!, $deployHash: String!, $timeStamp: Int!, $blockHash: String!){
// handleTransfer( pairAddress: $pairAddress, from: $from, to: $to, value: $value, deployHash: $deployHash, timeStamp: $timeStamp, blockHash: $blockHash) {
// id
// }

// }`,
// {pairAddress:'11f6e1b2d9566ab6d796f026b1d4bd36b71664c4ee8805fbc9cdca406607cd59', from: '0000000000000000000000000000000000000000000000000000000000000000', to: '0000000000000000000000000000000000000000000000000000000000000111', value: 5, pairAddress:'11f6e1b2d9566ab6d796f026b1d4bd36b71664c4ee8805fbc9cdca406607cd59', deployHash:'0000000000000000000000000000000000000000000000000000000000000000', timeStamp:1000, blockHash:'0000000000000000000000000000000000000000000000000000000000000000'})
// .then(data => console.log(data))
// .catch(error => console.error(error));

// request('http://localhost:3000/graphql',
// `mutation handleNewPair( $token0: String!, $token1: String!, $pair: String!, $all_pairs_length: Int!, $timeStamp: Int!, $blockHash: String!){
// handleNewPair( token0: $token0, token1: $token1, pair: $pair, all_pairs_length: $all_pairs_length, timeStamp: $timeStamp, blockHash: $blockHash) {
// id
// }

// }`,
// {token0:'51254d70d183f4b1e59ee5d5b0c76d3c3a81d0366278beecc05b546d49a9835c', token1: '96b0431770a34f5b651a43c830f3c8537e7c44f2cb8191d7efbcca2379785cda', pair: '11f6e1b2d9566ab6d796f026b1d4bd36b71664c4ee8805fbc9cdca406607cd59', all_pairs_length: 5, timeStamp:1000, blockHash:'0000000000000000000000000000000000000000000000000000000000000000'})
// .then(data => console.log(data))
// .catch(error => console.error(error));


// var data="Key::hash(45d8a07febaf15b0b0c5ace02533c9d278fd2b6e31b84e7a7abd0c7478e57ea2)";
// var from=data.split('(');
// var from1=from[1].split(')');
// console.log("from: ", from1[0]);
// var data1="1";

// console.log("from: ", parseInt(data1));

// var int=1635977242919;
// console.log("int: ",int.toString());


request('http://localhost:3000/graphql',
`mutation handleSync( $reserve0: Int!, $reserve1: Int!, $pairAddress: String!){
handleSync( reserve0: $reserve0, reserve1: $reserve1, pairAddress: $pairAddress) {
result
}
}`,
{reserve0:0, reserve1: 0, pairAddress: "c22c075df6da91e5c803ebc8914b12a215261c9d0cf28f637a9ce83b96f9842b"})
.then(data => console.log(data))
.catch(error => console.error(error));

0 comments on commit f1f4511

Please sign in to comment.