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

Commit

Permalink
userreservesagainstpair logic coded ... not tested ...
Browse files Browse the repository at this point in the history
  • Loading branch information
Hammad-Mubeen committed Feb 11, 2022
1 parent 35d9b22 commit 3e7cbd2
Show file tree
Hide file tree
Showing 7 changed files with 152 additions and 8 deletions.
4 changes: 2 additions & 2 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,9 @@ TOKEN_SYMBOL=DRAG
TOKEN_META=origin fire,lifetime infinite
CONTRACT_NAME=UniSwapRouter

CONTRACT_HASH=d94bf4c60244f127821ff12fe1f56299215d7056be3739e6c42c917768540a93
CONTRACT_HASH=92d411910dab397b0e0e9a4c25f8dc324e93259cc4cc14c7fe81839a8be4b752
PACKAGE_HASH=3de805e07efbc2cd9c5d323ab4fe5f2f0c1c5da33aec527d73de34a1fc9d3735
INSTALL_PAYMENT_AMOUNT=200000000000
INSTALL_PAYMENT_AMOUNT=300000000000
MINT_ONE_PAYMENT_AMOUNT=2000000000
MINT_COPIES_PAYMENT_AMOUNT=100000000000
BURN_ONE_PAYMENT_AMOUNT=12000000000
Expand Down
Binary file modified JsClients/ROUTER/wasm/uniswap-v2-router.wasm
Binary file not shown.
2 changes: 1 addition & 1 deletion graphql/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ async function createLiquidityPosition(exchange, user, value) {
});
if (liquidityTokenBalance === null) {
let pair = await Pair.findOne({ id: exchange });
pair.liquidityProviderCount = pair.liquidityProviderCount + ONE_BI;
pair.liquidityProviderCount = (BigInt(pair.liquidityProviderCount) + BigInt(ONE_BI)).toString();
liquidityTokenBalance = new LiquidityPosition({
id: exchange + "-" + user,
liquidityTokenBalance: value.toString(),
Expand Down
12 changes: 12 additions & 0 deletions models/pairagainstuser.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
var mongoose = require("mongoose");
var Schema = mongoose.Schema;

const pairagainstuserSchema = new Schema({
id: { type: String },
pair: { type: String },
reserve0: { type: String },
reserve1: { type: String },
});

var pairagainstuser = mongoose.model("pairagainstuser", pairagainstuserSchema);
module.exports = pairagainstuser;
34 changes: 34 additions & 0 deletions routes/deploypair.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ var express = require("express");
var router = express.Router();
var pair = require("../JsClients/PAIR/test/install.ts");
var pairsagainstuser = require("../models/pairsagainstuser");
var pairagainstuser = require("../models/pairagainstuser");
var pairsModel = require("../models/pair");

router.route("/makedeploypaircontract").post(async function (req, res, next) {
Expand Down Expand Up @@ -128,4 +129,37 @@ router.route("/getpairsagainstuser").post(async function (req, res, next) {
}
});

router.route("/getpairagainstuser").post(async function (req, res, next) {
try {
if (!req.body.user) {
return res.status(400).json({
success: false,
message: "user not found in request body",
});
}

let result = await pairagainstuser.find({
id: req.body.user.toLowerCase(),
});
if (result.length == 0) {
return res.status(400).json({
success: false,
message: "This user has not added liquidity against any pair.",
});
} else {
return res.status(200).json({
success: true,
message: "This User has added liquidity against following pairs.",
userpairs: result,
});
}
} catch (error) {
console.log("error (try-catch) : " + error);
return res.status(500).json({
success: false,
err: error,
});
}
});

module.exports = router;
86 changes: 83 additions & 3 deletions routes/listenerroutes.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ var { request } = require("graphql-request");
var pairModel = require("../models/pair");
var hashesofpairsModel = require("../models/hashesofpairs");
var eventsModel = require("../models/events");
var pairagainstuser = require("../models/pairagainstuser");

function splitdata(data) {
var temp = data.split("(");
Expand Down Expand Up @@ -61,9 +62,12 @@ router.route("/startListener").post(async function (req, res, next) {
}

await axios
.post("http://casperswapeventlistener-env.eba-hryscbuc.us-east-1.elasticbeanstalk.com/listener/initiateListener", {
contractPackageHashes: req.body.contractPackageHashes,
})
.post(
"http://casperswapeventlistener-env.eba-hryscbuc.us-east-1.elasticbeanstalk.com/listener/initiateListener",
{
contractPackageHashes: req.body.contractPackageHashes,
}
)
.then(function (response) {
console.log(response);
return res.status(200).json({
Expand Down Expand Up @@ -645,6 +649,82 @@ router.route("/geteventsdata").post(async function (req, res, next) {
console.log(error);
});
}
} else if (eventName == "addreserves") {
console.log(eventName + " Event result: ");
console.log(newData[0][0].data + " = " + newData[0][1].data);
console.log(newData[1][0].data + " = " + newData[1][1].data);
console.log(newData[2][0].data + " = " + newData[2][1].data);
console.log(newData[3][0].data + " = " + newData[3][1].data);
console.log(newData[4][0].data + " = " + newData[4][1].data);
console.log(newData[5][0].data + " = " + newData[5][1].data);

var user = splitdata(newData[2][1].data);
var pair = splitdata(newData[3][1].data);
var reserve0 = newData[4][1].data;
var reserve1 = newData[5][1].data;

console.log("user: ", user);
console.log("pair: ", pair);
console.log("reserve0: ", reserve0);
console.log("reserve1: ", reserve1);

let pairagainstuserresult = await pairagainstuser.findOne({
id: user,
pair: pair,
});
if (pairagainstuserresult == null) {
let newData = new pairagainstuser({
id: user,
pair: pair,
reserve0: reserve0,
reserve1: reserve1,
});
await pairagainstuser.create(newData);
} else {
pairagainstuserresult.reserve0 =
pairagainstuserresult.reserve0 + reserve0;
pairagainstuserresult.reserve1 =
pairagainstuserresult.reserve1 + reserve1;
await pairagainstuserresult.save();
}
} else if (eventName == "removereserves") {
console.log(eventName + " Event result: ");
console.log(newData[0][0].data + " = " + newData[0][1].data);
console.log(newData[1][0].data + " = " + newData[1][1].data);
console.log(newData[2][0].data + " = " + newData[2][1].data);
console.log(newData[3][0].data + " = " + newData[3][1].data);
console.log(newData[4][0].data + " = " + newData[4][1].data);
console.log(newData[5][0].data + " = " + newData[5][1].data);

var user = splitdata(newData[2][1].data);
var pair = splitdata(newData[3][1].data);
var reserve0 = newData[4][1].data;
var reserve1 = newData[5][1].data;

console.log("user: ", user);
console.log("pair: ", pair);
console.log("reserve0: ", reserve0);
console.log("reserve1: ", reserve1);

let pairagainstuserresult = await pairagainstuser.findOne({
id: user,
pair: pair,
});
if (pairagainstuserresult == null) {
let newData = new pairagainstuser({
id: user,
pair: pair,
reserve0: reserve0,
reserve1: reserve1,
});
await pairagainstuser.create(newData);
} else {
pairagainstuserresult.reserve0 =
pairagainstuserresult.reserve0 - reserve0;
pairagainstuserresult.reserve1 =
pairagainstuserresult.reserve1 - reserve1;
await pairagainstuserresult.save();
}
}
} catch (error) {
console.log("error (try-catch) : " + error);
Expand Down
22 changes: 20 additions & 2 deletions test.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,24 @@

// console.log("path: ",route.path('A', 'C'));

console.log(parseFloat("1000000000")/parseFloat("10000000000"));
console.log(0.1/parseFloat("10"));
// console.log(parseFloat("1000000000")/parseFloat("10000000000"));
// console.log(0.1/parseFloat("10"));

// let pairagainstuserresult = await pairagainstuser.findOne({
// id: args.to,
// pair: args.pairAddress,
// });
// if (pairagainstuserresult == null) {
// let newData = new pairagainstuser({
// id: args.to,
// pair: args.pairAddress,
// reserve0: args.amount0,
// reserve1: args.amount1,
// });
// await pairagainstuser.create(newData);
// } else {
// pairagainstuserresult.reserve0 = args.amount0;
// pairagainstuserresult.reserve1 = args.amount1;
// await pairagainstuserresult.save();
// }

0 comments on commit 3e7cbd2

Please sign in to comment.