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

Commit d1c3878

Browse files
committed
dayupdates function logic and working corrected (tested), tokensList Model and Endpoints created (tested)
1 parent a7904da commit d1c3878

File tree

14 files changed

+161
-30
lines changed

14 files changed

+161
-30
lines changed

JsClients/ERC20/keys/public_key.pem

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
-----BEGIN PUBLIC KEY-----
2-
MCowBQYDK2VwAyEALL3X/DHIFDBLlC2KxLdViyhGpsITRk9CC2z/dZGNwbo=
2+
MCowBQYDK2VwAyEA3+dK57Rtp6tCa8ok1Tc7nsBk58+yRje2BOR/jpXRd9M=
33
-----END PUBLIC KEY-----

JsClients/ERC20/keys/public_key_hex

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
012cbdd7fc31c814304b942d8ac4b7558b2846a6c213464f420b6cff75918dc1ba
1+
01dfe74ae7b46da7ab426bca24d5373b9ec064e7cfb24637b604e47f8e95d177d3

JsClients/ERC20/keys/secret_key.pem

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
-----BEGIN PRIVATE KEY-----
2-
MC4CAQAwBQYDK2VwBCIEIJ2oD3148IO8k5o4CXd0SEmC4cOwtQNp4hO0OMYGY+g6
2+
MC4CAQAwBQYDK2VwBCIEIAXbC6e4WdEjVyRrAD3RxaSDzw+vjnjoXfcYZXvZ/eS6
33
-----END PRIVATE KEY-----

JsClients/PAIR/src/pair.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import {
1919
import { PAIREvents } from "./constants";
2020
import * as utils from "./utils";
2121
import { RecipientType, IPendingDeploy } from "./types";
22+
import { consoleTestResultHandler } from "tslint/lib/test";
2223

2324
class PAIRClient {
2425
private contractName: string = "pair";
@@ -178,8 +179,9 @@ class PAIRClient {
178179
accountHash,
179180
this.namedKeys.balances
180181
);
181-
const maybeValue = result.value().unwrap();
182-
return maybeValue.value().toString();
182+
console.log("result: ",result);
183+
//const maybeValue = result.value().unwrap();
184+
//return maybeValue.value().toString();
183185
}
184186

185187

JsClients/PAIR/src/utils.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,8 @@ export const contractDictionaryGetter = async (
108108
dictionaryItemKey,
109109
seedUref
110110
);
111-
111+
112+
console.log(" storedValue: ", storedValue);
112113
if (storedValue && storedValue.CLValue instanceof CLValue) {
113114
return storedValue.CLValue!;
114115
} else {

JsClients/PAIR/test/installed.ts

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -451,11 +451,12 @@ const test = async () => {
451451
// console.log("... Token minted successfully");
452452

453453
// //balanceof
454-
let balance_router = await pair.balanceOf_router(ROUTERKEYS.publicKey);
455-
console.log(`... Balance: ${balance_router}`);
454+
// let balance_router = await pair.balanceOf_router(ROUTERKEYS.publicKey);
455+
// console.log(`... Balance: ${balance_router}`);
456456
//balanceof
457-
let balance = await pair.balanceOf((PAIR_CONTRACT_PACKAGE!).toLowerCase());
458-
console.log(`... Balance: ${balance}`);
457+
//await pair.balanceOf(("C83Fc787656Cf682e8C77A542C636bcA1d46d5f8C011B64ADB2c6596eD7E9280").toLowerCase());
458+
//await pair.balanceOf((PAIR_CONTRACT_PACKAGE!).toLowerCase());
459+
//console.log(`... Balance: ${balance}`);
459460

460461
// //sync
461462
// const syncDeployHash = await pair.sync(
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
-----BEGIN PUBLIC KEY-----
2-
MCowBQYDK2VwAyEALL3X/DHIFDBLlC2KxLdViyhGpsITRk9CC2z/dZGNwbo=
2+
MCowBQYDK2VwAyEA3+dK57Rtp6tCa8ok1Tc7nsBk58+yRje2BOR/jpXRd9M=
33
-----END PUBLIC KEY-----
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
012cbdd7fc31c814304b942d8ac4b7558b2846a6c213464f420b6cff75918dc1ba
1+
01dfe74ae7b46da7ab426bca24d5373b9ec064e7cfb24637b604e47f8e95d177d3
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
-----BEGIN PRIVATE KEY-----
2-
MC4CAQAwBQYDK2VwBCIEIJ2oD3148IO8k5o4CXd0SEmC4cOwtQNp4hO0OMYGY+g6
2+
MC4CAQAwBQYDK2VwBCIEIAXbC6e4WdEjVyRrAD3RxaSDzw+vjnjoXfcYZXvZ/eS6
33
-----END PRIVATE KEY-----

app.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ require("dotenv").config();
1010
const { graphqlHTTP } = require("express-graphql");
1111
const schema = require("./graphql/schema");
1212
var listenerRouter = require('./routes/listenerroutes');
13+
var tokensListRouter = require('./routes/tokensList');
1314

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

6971
app.use('/graphql', graphqlHTTP({
7072
schema: schema,

graphql/dayUpdates.js

Lines changed: 45 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ const {
1818
async function updateUniswapDayData (timeStamp) {
1919

2020
try {
21+
console.log("hello.");
2122
let uniswap = await UniswapFactory.findOne({
2223
id: process.env.FACTORY_CONTRACT,
2324
});
@@ -29,21 +30,29 @@ async function updateUniswapDayData (timeStamp) {
2930
id: dayID.toString(),
3031
});
3132
if (uniswapDayData === null) {
32-
uniswapDayData = new UniswapDayData({
33+
let newData = new UniswapDayData({
3334
id: (parseInt(dayID)).toString(),
3435
date: parseInt(dayStartTimestamp),
3536
dailyVolumeUSD: ZERO_BD,
3637
dailyVolumeETH: ZERO_BD,
3738
totalVolumeUSD: ZERO_BD,
3839
totalVolumeETH: ZERO_BD,
3940
dailyVolumeUntracked: ZERO_BD,
41+
uniswapDaytotalLiquidityUSD : uniswap.totalLiquidityUSD,
42+
totalLiquidityETH : uniswap.totalLiquidityETH,
43+
txCount : uniswap.txCount
4044
});
45+
let newdocument = await UniswapDayData.create(newData);
46+
console.log("newdocument: ",newdocument);
47+
return newdocument;
4148
}
4249
uniswapDayData.totalLiquidityUSD = uniswap.totalLiquidityUSD;
4350
uniswapDayData.totalLiquidityETH = uniswap.totalLiquidityETH;
4451
uniswapDayData.txCount = uniswap.txCount;
4552
await uniswapDayData.save();
4653

54+
console.log("uniswapDayData: ",uniswapDayData);
55+
4756
return uniswapDayData;
4857

4958
} catch (error) {
@@ -64,7 +73,7 @@ async function updatePairDayData (timeStamp,pairAddress){
6473
let pair = await Pair.findOne({ id: pairAddress });
6574
let pairDayData = await PairDayData.findOne({ id: dayPairID });
6675
if (pairDayData === null) {
67-
pairDayData = new PairDayData({
76+
let newData = new PairDayData({
6877
id: dayPairID,
6978
date: parseInt(dayStartTimestamp),
7079
token0: pair.token0.id,
@@ -74,16 +83,25 @@ async function updatePairDayData (timeStamp,pairAddress){
7483
dailyVolumeToken1: ZERO_BD,
7584
dailyVolumeUSD: ZERO_BD,
7685
dailyTxns: ZERO_BI,
86+
totalSupply : pair.totalSupply,
87+
reserve0 : pair.reserve0,
88+
reserve1 : pair.reserve1,
89+
reserveUSD : pair.reserveUSD,
90+
dailyTxns : ONE_BI
7791
});
92+
let newdocument = await PairDayData.create(newData);
93+
console.log("newdocument: ",newdocument);
94+
return newdocument;
7895
}
79-
8096
pairDayData.totalSupply = pair.totalSupply;
8197
pairDayData.reserve0 = pair.reserve0;
8298
pairDayData.reserve1 = pair.reserve1;
8399
pairDayData.reserveUSD = pair.reserveUSD;
84100
pairDayData.dailyTxns = pairDayData.dailyTxns + ONE_BI;
85101
await pairDayData.save();
86102

103+
console.log("pairDayData: ",pairDayData);
104+
87105
return pairDayData;
88106
} catch (error) {
89107
throw new Error(error);
@@ -103,15 +121,23 @@ async function updatePairHourData (timeStamp,pairAddress){
103121
let pair = await Pair.findOne({ id: pairAddress });
104122
let pairHourData = await PairHourData.findOne({ id: hourPairID });
105123
if (pairHourData === null) {
106-
pairHourData = new PairHourData({
124+
let newData = new PairHourData({
107125
id: hourPairID,
108126
hourStartUnix: parseInt(hourStartUnix),
109127
pair: pairAddress,
110128
hourlyVolumeToken0: ZERO_BD,
111129
hourlyVolumeToken1: ZERO_BD,
112130
hourlyVolumeUSD: ZERO_BD,
113-
hourlyTxns: ZERO_BI,
131+
hourlyTxns : ZERO_BI,
132+
totalSupply : pair.totalSupply,
133+
reserve0 : pair.reserve0,
134+
reserve1 : pair.reserve1,
135+
reserveUSD : pair.reserveUSD,
136+
hourlyTxns : ONE_BI
114137
});
138+
let newdocument = await PairHourData.create(newData);
139+
console.log("newdocument: ",newdocument);
140+
return newdocument;
115141
}
116142

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

150+
console.log("pairHourData: ",pairHourData);
151+
124152
return pairHourData;
125153
} catch (error) {
126154
throw new Error(error);
@@ -141,7 +169,7 @@ async function updateTokenDayData (token,timeStamp) {
141169
let tokenDayData = await TokenDayData.findOne({ id: tokenDayID });
142170
let tokendata = await Token.findOne({ id: token.id });
143171
if (tokenDayData === null) {
144-
tokenDayData = new TokenDayData({
172+
let newData = new TokenDayData({
145173
id: tokenDayID,
146174
date: parseInt(dayStartTimestamp),
147175
token: token.id,
@@ -151,8 +179,17 @@ async function updateTokenDayData (token,timeStamp) {
151179
dailyVolumeUSD: ZERO_BD,
152180
dailyTxns: ZERO_BI,
153181
totalLiquidityUSD: ZERO_BD,
182+
priceUSD : tokendata.derivedETH * bundle.ethPrice,
183+
totalLiquidityToken : tokendata.totalLiquidity,
184+
totalLiquidityETH : tokendata.totalLiquidity * tokendata.derivedETH,
185+
totalLiquidityUSD : (tokendata.totalLiquidity * tokendata.derivedETH) * bundle.ethPrice,
186+
dailyTxns : ONE_BI
154187
});
188+
let newdocument = await TokenDayData.create(newData);
189+
console.log("newdocument: ",newdocument);
190+
return newdocument;
155191
}
192+
156193
tokenDayData.priceUSD = tokendata.derivedETH * bundle.ethPrice;
157194
tokenDayData.totalLiquidityToken = tokendata.totalLiquidity;
158195
tokenDayData.totalLiquidityETH =
@@ -162,6 +199,8 @@ async function updateTokenDayData (token,timeStamp) {
162199
tokenDayData.dailyTxns = tokenDayData.dailyTxns + ONE_BI;
163200
await tokenDayData.save();
164201

202+
console.log("tokenDayData: ",tokenDayData);
203+
165204
return tokenDayData;
166205
} catch (error) {
167206
throw new Error(error);

graphql/mutations.js

Lines changed: 21 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -717,6 +717,8 @@ const handleTransfer = {
717717
if (from != ADDRESS_ZERO && from != pair.id) {
718718
console.log("burn2");
719719
//let Balance =await PairContract.balanceOf(args.pairAddress,from.toLowerCase());
720+
//console.log("Balance at "+from+" is = "+ Balance);
721+
720722
let Balance=2000;
721723
await createLiquidityPosition(args.pairAddress, from, Balance);
722724

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

733735
if (to != ADDRESS_ZERO && to != pair.id) {
734736
console.log("burn3");
735-
//let Balance =await PairContract.balanceOf(args.pairAddress,to.toLowerCase());
737+
//let Balance =await PairContract.balanceOf(args.pairAddress,to.toLowerCase());
738+
//console.log("Balance at "+to+" is = "+ Balance);
739+
736740
let Balance=2000;
737741
await createLiquidityPosition(args.pairAddress, to, Balance);
738742

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

954-
await uniswapDayData.save();
955-
await pairDayData.save();
956-
await pairHourData.save();
957-
await token0DayData.save();
958-
await token1DayData.save();
958+
console.log("pairDayData: ",pairDayData);
959+
console.log("pairHourData: ",pairHourData);
960+
console.log("uniswapDayData: ",uniswapDayData);
961+
console.log("token0DayData: ",token0DayData);
962+
console.log("token1DayData: ",token1DayData);
959963

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

1067-
await uniswapDayData.save();
1068-
await pairDayData.save();
1069-
await pairHourData.save();
1070-
await token0DayData.save();
1071-
await token1DayData.save();
1071+
console.log("pairDayData: ",pairDayData);
1072+
console.log("pairHourData: ",pairHourData);
1073+
console.log("uniswapDayData: ",uniswapDayData);
1074+
console.log("token0DayData: ",token0DayData);
1075+
console.log("token1DayData: ",token1DayData);
10721076

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

1254+
console.log("pairDayData: ",pairDayData);
1255+
console.log("pairHourData: ",pairHourData);
1256+
console.log("uniswapDayData: ",uniswapDayData);
1257+
console.log("token0DayData: ",token0DayData);
1258+
console.log("token1DayData: ",token1DayData);
1259+
12501260
// swap specific updating
12511261
uniswapDayData.dailyVolumeUSD =
12521262
uniswapDayData.dailyVolumeUSD + trackedAmountUSD;

models/tokensList.js

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
var mongoose = require('mongoose');
2+
var Schema = mongoose.Schema;
3+
4+
const tokensListSchema = new Schema({
5+
6+
//tokens Data
7+
data: {
8+
type: Object,
9+
}
10+
11+
});
12+
13+
var tokensList = mongoose.model("tokensList", tokensListSchema);
14+
module.exports = tokensList;

routes/tokenslist.js

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
require('dotenv').config()
2+
var express = require('express');
3+
var router = express.Router();
4+
var tokensListModel=require('../models/tokensList');
5+
6+
router.route("/addtokensList").post(async function (req, res, next) {
7+
try {
8+
9+
if(!req.body.tokensList)
10+
{
11+
return res.status(400).json({
12+
success: false,
13+
message: "tokensList not found in the request Body.",
14+
});
15+
}
16+
let newData= new tokensListModel({
17+
data:req.body.tokensList
18+
});
19+
await tokensListModel.create(newData);
20+
21+
return res.status(200).json({
22+
success: true,
23+
message: "Token List Data SuccessFully Saved."
24+
});
25+
26+
} catch (error) {
27+
console.log("error (try-catch) : " + error);
28+
return res.status(500).json({
29+
success: false,
30+
err: error,
31+
});
32+
}
33+
});
34+
35+
router.route("/tokensList").get(async function (req, res, next) {
36+
try {
37+
38+
var tokensList= await tokensListModel.findOne({});
39+
if(tokensList==null)
40+
{
41+
return res.status(400).json({
42+
success: false,
43+
message: "There is no data in tokensList Collection.",
44+
});
45+
}
46+
return res.status(200).json({
47+
success: true,
48+
message: "Token List Data: ",
49+
data: tokensList.data
50+
});
51+
52+
} catch (error) {
53+
console.log("error (try-catch) : " + error);
54+
return res.status(500).json({
55+
success: false,
56+
err: error,
57+
});
58+
}
59+
});
60+
61+
62+
module.exports = router;

0 commit comments

Comments
 (0)