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

Commit

Permalink
dayupdates function logic and working corrected (tested), tokensList …
Browse files Browse the repository at this point in the history
…Model and Endpoints created (tested)
  • Loading branch information
Hammad-Mubeen committed Dec 22, 2021
1 parent a7904da commit d1c3878
Show file tree
Hide file tree
Showing 14 changed files with 161 additions and 30 deletions.
2 changes: 1 addition & 1 deletion JsClients/ERC20/keys/public_key.pem
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
-----BEGIN PUBLIC KEY-----
MCowBQYDK2VwAyEALL3X/DHIFDBLlC2KxLdViyhGpsITRk9CC2z/dZGNwbo=
MCowBQYDK2VwAyEA3+dK57Rtp6tCa8ok1Tc7nsBk58+yRje2BOR/jpXRd9M=
-----END PUBLIC KEY-----
2 changes: 1 addition & 1 deletion JsClients/ERC20/keys/public_key_hex
Original file line number Diff line number Diff line change
@@ -1 +1 @@
012cbdd7fc31c814304b942d8ac4b7558b2846a6c213464f420b6cff75918dc1ba
01dfe74ae7b46da7ab426bca24d5373b9ec064e7cfb24637b604e47f8e95d177d3
2 changes: 1 addition & 1 deletion JsClients/ERC20/keys/secret_key.pem
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
-----BEGIN PRIVATE KEY-----
MC4CAQAwBQYDK2VwBCIEIJ2oD3148IO8k5o4CXd0SEmC4cOwtQNp4hO0OMYGY+g6
MC4CAQAwBQYDK2VwBCIEIAXbC6e4WdEjVyRrAD3RxaSDzw+vjnjoXfcYZXvZ/eS6
-----END PRIVATE KEY-----
6 changes: 4 additions & 2 deletions JsClients/PAIR/src/pair.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import {
import { PAIREvents } from "./constants";
import * as utils from "./utils";
import { RecipientType, IPendingDeploy } from "./types";
import { consoleTestResultHandler } from "tslint/lib/test";

class PAIRClient {
private contractName: string = "pair";
Expand Down Expand Up @@ -178,8 +179,9 @@ class PAIRClient {
accountHash,
this.namedKeys.balances
);
const maybeValue = result.value().unwrap();
return maybeValue.value().toString();
console.log("result: ",result);
//const maybeValue = result.value().unwrap();
//return maybeValue.value().toString();
}


Expand Down
3 changes: 2 additions & 1 deletion JsClients/PAIR/src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,8 @@ export const contractDictionaryGetter = async (
dictionaryItemKey,
seedUref
);


console.log(" storedValue: ", storedValue);
if (storedValue && storedValue.CLValue instanceof CLValue) {
return storedValue.CLValue!;
} else {
Expand Down
9 changes: 5 additions & 4 deletions JsClients/PAIR/test/installed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -451,11 +451,12 @@ const test = async () => {
// console.log("... Token minted successfully");

// //balanceof
let balance_router = await pair.balanceOf_router(ROUTERKEYS.publicKey);
console.log(`... Balance: ${balance_router}`);
// let balance_router = await pair.balanceOf_router(ROUTERKEYS.publicKey);
// console.log(`... Balance: ${balance_router}`);
//balanceof
let balance = await pair.balanceOf((PAIR_CONTRACT_PACKAGE!).toLowerCase());
console.log(`... Balance: ${balance}`);
//await pair.balanceOf(("C83Fc787656Cf682e8C77A542C636bcA1d46d5f8C011B64ADB2c6596eD7E9280").toLowerCase());
//await pair.balanceOf((PAIR_CONTRACT_PACKAGE!).toLowerCase());
//console.log(`... Balance: ${balance}`);

// //sync
// const syncDeployHash = await pair.sync(
Expand Down
2 changes: 1 addition & 1 deletion JsClients/keys/erc20keys/public_key.pem
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
-----BEGIN PUBLIC KEY-----
MCowBQYDK2VwAyEALL3X/DHIFDBLlC2KxLdViyhGpsITRk9CC2z/dZGNwbo=
MCowBQYDK2VwAyEA3+dK57Rtp6tCa8ok1Tc7nsBk58+yRje2BOR/jpXRd9M=
-----END PUBLIC KEY-----
2 changes: 1 addition & 1 deletion JsClients/keys/erc20keys/public_key_hex
Original file line number Diff line number Diff line change
@@ -1 +1 @@
012cbdd7fc31c814304b942d8ac4b7558b2846a6c213464f420b6cff75918dc1ba
01dfe74ae7b46da7ab426bca24d5373b9ec064e7cfb24637b604e47f8e95d177d3
2 changes: 1 addition & 1 deletion JsClients/keys/erc20keys/secret_key.pem
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
-----BEGIN PRIVATE KEY-----
MC4CAQAwBQYDK2VwBCIEIJ2oD3148IO8k5o4CXd0SEmC4cOwtQNp4hO0OMYGY+g6
MC4CAQAwBQYDK2VwBCIEIAXbC6e4WdEjVyRrAD3RxaSDzw+vjnjoXfcYZXvZ/eS6
-----END PRIVATE KEY-----
2 changes: 2 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ require("dotenv").config();
const { graphqlHTTP } = require("express-graphql");
const schema = require("./graphql/schema");
var listenerRouter = require('./routes/listenerroutes');
var tokensListRouter = require('./routes/tokensList');

// view engine setup
app.set('views', path.join(__dirname, 'views'));
Expand Down Expand Up @@ -65,6 +66,7 @@ app.get("/", (req, res) => {
res.json({ msg: "Uniswap V2 GraphQL Server" });
});
app.use('/', listenerRouter);
app.use('/', tokensListRouter);

app.use('/graphql', graphqlHTTP({
schema: schema,
Expand Down
51 changes: 45 additions & 6 deletions graphql/dayUpdates.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ const {
async function updateUniswapDayData (timeStamp) {

try {
console.log("hello.");
let uniswap = await UniswapFactory.findOne({
id: process.env.FACTORY_CONTRACT,
});
Expand All @@ -29,21 +30,29 @@ async function updateUniswapDayData (timeStamp) {
id: dayID.toString(),
});
if (uniswapDayData === null) {
uniswapDayData = new UniswapDayData({
let newData = new UniswapDayData({
id: (parseInt(dayID)).toString(),
date: parseInt(dayStartTimestamp),
dailyVolumeUSD: ZERO_BD,
dailyVolumeETH: ZERO_BD,
totalVolumeUSD: ZERO_BD,
totalVolumeETH: ZERO_BD,
dailyVolumeUntracked: ZERO_BD,
uniswapDaytotalLiquidityUSD : uniswap.totalLiquidityUSD,
totalLiquidityETH : uniswap.totalLiquidityETH,
txCount : uniswap.txCount
});
let newdocument = await UniswapDayData.create(newData);
console.log("newdocument: ",newdocument);
return newdocument;
}
uniswapDayData.totalLiquidityUSD = uniswap.totalLiquidityUSD;
uniswapDayData.totalLiquidityETH = uniswap.totalLiquidityETH;
uniswapDayData.txCount = uniswap.txCount;
await uniswapDayData.save();

console.log("uniswapDayData: ",uniswapDayData);

return uniswapDayData;

} catch (error) {
Expand All @@ -64,7 +73,7 @@ async function updatePairDayData (timeStamp,pairAddress){
let pair = await Pair.findOne({ id: pairAddress });
let pairDayData = await PairDayData.findOne({ id: dayPairID });
if (pairDayData === null) {
pairDayData = new PairDayData({
let newData = new PairDayData({
id: dayPairID,
date: parseInt(dayStartTimestamp),
token0: pair.token0.id,
Expand All @@ -74,16 +83,25 @@ async function updatePairDayData (timeStamp,pairAddress){
dailyVolumeToken1: ZERO_BD,
dailyVolumeUSD: ZERO_BD,
dailyTxns: ZERO_BI,
totalSupply : pair.totalSupply,
reserve0 : pair.reserve0,
reserve1 : pair.reserve1,
reserveUSD : pair.reserveUSD,
dailyTxns : ONE_BI
});
let newdocument = await PairDayData.create(newData);
console.log("newdocument: ",newdocument);
return newdocument;
}

pairDayData.totalSupply = pair.totalSupply;
pairDayData.reserve0 = pair.reserve0;
pairDayData.reserve1 = pair.reserve1;
pairDayData.reserveUSD = pair.reserveUSD;
pairDayData.dailyTxns = pairDayData.dailyTxns + ONE_BI;
await pairDayData.save();

console.log("pairDayData: ",pairDayData);

return pairDayData;
} catch (error) {
throw new Error(error);
Expand All @@ -103,15 +121,23 @@ async function updatePairHourData (timeStamp,pairAddress){
let pair = await Pair.findOne({ id: pairAddress });
let pairHourData = await PairHourData.findOne({ id: hourPairID });
if (pairHourData === null) {
pairHourData = new PairHourData({
let newData = new PairHourData({
id: hourPairID,
hourStartUnix: parseInt(hourStartUnix),
pair: pairAddress,
hourlyVolumeToken0: ZERO_BD,
hourlyVolumeToken1: ZERO_BD,
hourlyVolumeUSD: ZERO_BD,
hourlyTxns: ZERO_BI,
hourlyTxns : ZERO_BI,
totalSupply : pair.totalSupply,
reserve0 : pair.reserve0,
reserve1 : pair.reserve1,
reserveUSD : pair.reserveUSD,
hourlyTxns : ONE_BI
});
let newdocument = await PairHourData.create(newData);
console.log("newdocument: ",newdocument);
return newdocument;
}

pairHourData.totalSupply = pair.totalSupply;
Expand All @@ -121,6 +147,8 @@ async function updatePairHourData (timeStamp,pairAddress){
pairHourData.hourlyTxns = pairHourData.hourlyTxns + ONE_BI;
await pairHourData.save();

console.log("pairHourData: ",pairHourData);

return pairHourData;
} catch (error) {
throw new Error(error);
Expand All @@ -141,7 +169,7 @@ async function updateTokenDayData (token,timeStamp) {
let tokenDayData = await TokenDayData.findOne({ id: tokenDayID });
let tokendata = await Token.findOne({ id: token.id });
if (tokenDayData === null) {
tokenDayData = new TokenDayData({
let newData = new TokenDayData({
id: tokenDayID,
date: parseInt(dayStartTimestamp),
token: token.id,
Expand All @@ -151,8 +179,17 @@ async function updateTokenDayData (token,timeStamp) {
dailyVolumeUSD: ZERO_BD,
dailyTxns: ZERO_BI,
totalLiquidityUSD: ZERO_BD,
priceUSD : tokendata.derivedETH * bundle.ethPrice,
totalLiquidityToken : tokendata.totalLiquidity,
totalLiquidityETH : tokendata.totalLiquidity * tokendata.derivedETH,
totalLiquidityUSD : (tokendata.totalLiquidity * tokendata.derivedETH) * bundle.ethPrice,
dailyTxns : ONE_BI
});
let newdocument = await TokenDayData.create(newData);
console.log("newdocument: ",newdocument);
return newdocument;
}

tokenDayData.priceUSD = tokendata.derivedETH * bundle.ethPrice;
tokenDayData.totalLiquidityToken = tokendata.totalLiquidity;
tokenDayData.totalLiquidityETH =
Expand All @@ -162,6 +199,8 @@ async function updateTokenDayData (token,timeStamp) {
tokenDayData.dailyTxns = tokenDayData.dailyTxns + ONE_BI;
await tokenDayData.save();

console.log("tokenDayData: ",tokenDayData);

return tokenDayData;
} catch (error) {
throw new Error(error);
Expand Down
32 changes: 21 additions & 11 deletions graphql/mutations.js
Original file line number Diff line number Diff line change
Expand Up @@ -717,6 +717,8 @@ const handleTransfer = {
if (from != ADDRESS_ZERO && from != pair.id) {
console.log("burn2");
//let Balance =await PairContract.balanceOf(args.pairAddress,from.toLowerCase());
//console.log("Balance at "+from+" is = "+ Balance);

let Balance=2000;
await createLiquidityPosition(args.pairAddress, from, Balance);

Expand All @@ -732,7 +734,9 @@ const handleTransfer = {

if (to != ADDRESS_ZERO && to != pair.id) {
console.log("burn3");
//let Balance =await PairContract.balanceOf(args.pairAddress,to.toLowerCase());
//let Balance =await PairContract.balanceOf(args.pairAddress,to.toLowerCase());
//console.log("Balance at "+to+" is = "+ Balance);

let Balance=2000;
await createLiquidityPosition(args.pairAddress, to, Balance);

Expand Down Expand Up @@ -951,11 +955,11 @@ const handleMint = {
token0DayData = await updateTokenDayData(token0,parseInt(parseInt(args.timeStamp)/1000));
token1DayData = await updateTokenDayData(token1,parseInt(parseInt(args.timeStamp)/1000));

await uniswapDayData.save();
await pairDayData.save();
await pairHourData.save();
await token0DayData.save();
await token1DayData.save();
console.log("pairDayData: ",pairDayData);
console.log("pairHourData: ",pairHourData);
console.log("uniswapDayData: ",uniswapDayData);
console.log("token0DayData: ",token0DayData);
console.log("token1DayData: ",token1DayData);

let response = await Response.findOne({ id: "1" });
if(response=== null)
Expand Down Expand Up @@ -1064,11 +1068,11 @@ const handleBurn = {
token0DayData = await updateTokenDayData(token0,parseInt(parseInt(args.timeStamp)/1000));
token1DayData = await updateTokenDayData(token1,parseInt(parseInt(args.timeStamp)/1000));

await uniswapDayData.save();
await pairDayData.save();
await pairHourData.save();
await token0DayData.save();
await token1DayData.save();
console.log("pairDayData: ",pairDayData);
console.log("pairHourData: ",pairHourData);
console.log("uniswapDayData: ",uniswapDayData);
console.log("token0DayData: ",token0DayData);
console.log("token1DayData: ",token1DayData);

let response = await Response.findOne({ id: "1" });
if(response=== null)
Expand Down Expand Up @@ -1247,6 +1251,12 @@ const handleSwap = {
token0DayData = await updateTokenDayData(token0,parseInt(parseInt(args.timeStamp)/1000));
token1DayData = await updateTokenDayData(token1,parseInt(parseInt(args.timeStamp)/1000));

console.log("pairDayData: ",pairDayData);
console.log("pairHourData: ",pairHourData);
console.log("uniswapDayData: ",uniswapDayData);
console.log("token0DayData: ",token0DayData);
console.log("token1DayData: ",token1DayData);

// swap specific updating
uniswapDayData.dailyVolumeUSD =
uniswapDayData.dailyVolumeUSD + trackedAmountUSD;
Expand Down
14 changes: 14 additions & 0 deletions models/tokensList.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
var mongoose = require('mongoose');
var Schema = mongoose.Schema;

const tokensListSchema = new Schema({

//tokens Data
data: {
type: Object,
}

});

var tokensList = mongoose.model("tokensList", tokensListSchema);
module.exports = tokensList;
62 changes: 62 additions & 0 deletions routes/tokenslist.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
require('dotenv').config()
var express = require('express');
var router = express.Router();
var tokensListModel=require('../models/tokensList');

router.route("/addtokensList").post(async function (req, res, next) {
try {

if(!req.body.tokensList)
{
return res.status(400).json({
success: false,
message: "tokensList not found in the request Body.",
});
}
let newData= new tokensListModel({
data:req.body.tokensList
});
await tokensListModel.create(newData);

return res.status(200).json({
success: true,
message: "Token List Data SuccessFully Saved."
});

} catch (error) {
console.log("error (try-catch) : " + error);
return res.status(500).json({
success: false,
err: error,
});
}
});

router.route("/tokensList").get(async function (req, res, next) {
try {

var tokensList= await tokensListModel.findOne({});
if(tokensList==null)
{
return res.status(400).json({
success: false,
message: "There is no data in tokensList Collection.",
});
}
return res.status(200).json({
success: true,
message: "Token List Data: ",
data: tokensList.data
});

} catch (error) {
console.log("error (try-catch) : " + error);
return res.status(500).json({
success: false,
err: error,
});
}
});


module.exports = router;

0 comments on commit d1c3878

Please sign in to comment.