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

Commit

Permalink
when liquidity zero delete pair against user DONE and tested
Browse files Browse the repository at this point in the history
  • Loading branch information
Hammad-Mubeen committed Feb 13, 2022
1 parent 775a320 commit 6be8ec5
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 24 deletions.
27 changes: 21 additions & 6 deletions routes/deploypair.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ var pair = require("../JsClients/PAIR/test/install.ts");
var pairsagainstuser = require("../models/pairsagainstuser");
var pairagainstuser = require("../models/pairagainstuser");
var pairsModel = require("../models/pair");
var pair = require("../JsClients/PAIR/test/installed.ts");
const { reset } = require("nodemon");

router.route("/makedeploypaircontract").post(async function (req, res, next) {
try {
Expand Down Expand Up @@ -147,17 +149,30 @@ router.route("/getpairagainstuser").post(async function (req, res, next) {
message: "This user has not added liquidity against any pair.",
});
} else {
let pairsdata=[];
for(var i=0;i<result.length;i++)
{
let pairsresult = await pairsModel.findOne({id:result[i].pair});
for (var i = 0; i < result.length; i++) {
let liquidity = await pair.balanceOf(
result[i].pair,
result[i].id.toLowerCase()
);
if (liquidity == "0") {
await pairagainstuser.deleteOne({ _id: result[i]._id });
}
}
let result1 = await pairagainstuser.find({
id: req.body.user.toLowerCase(),
});

let pairsdata = [];
for (var i = 0; i < result1.length; i++) {
let pairsresult = await pairsModel.findOne({ id: result1[i].pair });
pairsdata.push(pairsresult);
}

return res.status(200).json({
success: true,
message: "This User has added liquidity against following pairs.",
userpairs: result,
pairsdata:pairsdata
userpairs: result1,
pairsdata: pairsdata,
});
}
} catch (error) {
Expand Down
25 changes: 7 additions & 18 deletions routes/listenerroutes.js
Original file line number Diff line number Diff line change
Expand Up @@ -721,24 +721,13 @@ router.route("/geteventsdata").post(async function (req, res, next) {
});
await pairagainstuser.create(newData);
} else {
if (
(
BigInt(pairagainstuserresult.reserve0) - BigInt(reserve0)
).toString() == "0" &&
(
BigInt(pairagainstuserresult.reserve1) - BigInt(reserve1)
).toString() == "0"
) {
await pairagainstuser.deleteOne({ _id: pairagainstuserresult._id });
} else {
pairagainstuserresult.reserve0 = (
BigInt(pairagainstuserresult.reserve0) - BigInt(reserve0)
).toString();
pairagainstuserresult.reserve1 = (
BigInt(pairagainstuserresult.reserve1) - BigInt(reserve1)
).toString();
await pairagainstuserresult.save();
}
pairagainstuserresult.reserve0 = (
BigInt(pairagainstuserresult.reserve0) - BigInt(reserve0)
).toString();
pairagainstuserresult.reserve1 = (
BigInt(pairagainstuserresult.reserve1) - BigInt(reserve1)
).toString();
await pairagainstuserresult.save();
}
}
} catch (error) {
Expand Down

0 comments on commit 6be8ec5

Please sign in to comment.