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

Commit

Permalink
addreserve and removereserve logic updated
Browse files Browse the repository at this point in the history
  • Loading branch information
Hammad-Mubeen committed Apr 18, 2022
1 parent f011f01 commit 52c1bf0
Show file tree
Hide file tree
Showing 2 changed files with 104 additions and 33 deletions.
22 changes: 11 additions & 11 deletions JsClients/ERC20/test/installed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ const erc20 = new ERC20Client(
const test = async () => {

await erc20.setContractHash(TOKEN1_CONTRACT!);
console.log("contract:"+ TOKEN1_CONTRACT!);
//console.log("contract:"+ TOKEN1_CONTRACT!);
//getTotalSupply(TOKEN1_CONTRACT!);
// // //name
// // const name = await erc20.name();
Expand Down Expand Up @@ -115,16 +115,16 @@ const test = async () => {
// console.log("... Token minted successfully.");

//mint
// const mintDeployHash = await erc20.mint(
// ROUTERKEYS,
// "0d72ccd15e717fde4afc91fab70cb20e9986da52c670976386efc91b375f52a8",
// MINT_AMOUNT!,
// MINT_PAYMENT_AMOUNT!
// );
// console.log("... Mint deploy hash: ", mintDeployHash);

// await getDeploy(NODE_ADDRESS!, mintDeployHash);
// console.log("... Token minted successfully.");
const mintDeployHash = await erc20.mint(
ROUTERKEYS,
"386859a25c3f8355d663fe7bb8a2cad36efa65292ef073b2fbadef8da8f976f2",
MINT_AMOUNT!,
MINT_PAYMENT_AMOUNT!
);
console.log("... Mint deploy hash: ", mintDeployHash);

await getDeploy(NODE_ADDRESS!, mintDeployHash);
console.log("... Token minted successfully.");

// balanceof
// let balance = await erc20.balanceOfcontract(PAIR_CONTRACT!);
Expand Down
115 changes: 93 additions & 22 deletions routes/listenerroutes.js
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,14 @@ router
}

let packageHash = req.body.packageHash.toLowerCase();
let contractHash= await allcontractsDataModel.findOne({packageHash:packageHash});
let contractHash = await allcontractsDataModel.findOne({
packageHash: packageHash,
});

return res.status(200).json({
success: true,
message: "Contract Hash has been Succefully found.",
Data:contractHash
Data: contractHash,
});
} catch (error) {
console.log("error (try-catch) : " + error);
Expand All @@ -129,9 +131,12 @@ router.route("/startListener").post(async function (req, res, next) {
}

await axios
.post( "http://casperswaplistenerbackend-env.eba-rbumbt2m.us-east-1.elasticbeanstalk.com/listener/initiateListener", {
contractPackageHashes: req.body.contractPackageHashes,
})
.post(
"http://casperswaplistenerbackend-env.eba-rbumbt2m.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 @@ -288,10 +293,10 @@ router.route("/geteventsdata").post(async function (req, res, next) {
"there are no contract and package hash found in the database.",
});
}
var packageHash=null;
var packageHash = null;
for (var i = 0; i < pairsresult.length; i++) {
if (pairsresult[i].packageHash.toLowerCase() == to.toLowerCase()) {
packageHash=pairsresult[i].packageHash.toLowerCase();
packageHash = pairsresult[i].packageHash.toLowerCase();
console.log("packageHash: ", packageHash);
}
}
Expand Down Expand Up @@ -749,13 +754,47 @@ router.route("/geteventsdata").post(async function (req, res, next) {
message: "Pair against User with reserves created Successfully.",
});
} else {
pairagainstuserresult.reserve0 = (
BigInt(pairagainstuserresult.reserve0) + BigInt(reserve0)
).toString();
pairagainstuserresult.reserve1 = (
BigInt(pairagainstuserresult.reserve1) + BigInt(reserve1)
).toString();
await pairagainstuserresult.save();
if (
BigInt(pairagainstuserresult.reserve0) >
BigInt(pairagainstuserresult.reserve1)
) {
if (BigInt(reserve0) > BigInt(reserve1)) {
pairagainstuserresult.reserve0 = (
BigInt(pairagainstuserresult.reserve0) + BigInt(reserve0)
).toString();
pairagainstuserresult.reserve1 = (
BigInt(pairagainstuserresult.reserve1) + BigInt(reserve1)
).toString();
await pairagainstuserresult.save();
} else {
pairagainstuserresult.reserve0 = (
BigInt(pairagainstuserresult.reserve0) + BigInt(reserve1)
).toString();
pairagainstuserresult.reserve1 = (
BigInt(pairagainstuserresult.reserve1) + BigInt(reserve0)
).toString();
await pairagainstuserresult.save();
}
} else {
if (BigInt(reserve1) > BigInt(reserve0)) {
pairagainstuserresult.reserve0 = (
BigInt(pairagainstuserresult.reserve0) + BigInt(reserve0)
).toString();
pairagainstuserresult.reserve1 = (
BigInt(pairagainstuserresult.reserve1) + BigInt(reserve1)
).toString();
await pairagainstuserresult.save();
} else {
pairagainstuserresult.reserve0 = (
BigInt(pairagainstuserresult.reserve0) + BigInt(reserve1)
).toString();
pairagainstuserresult.reserve1 = (
BigInt(pairagainstuserresult.reserve1) + BigInt(reserve0)
).toString();
await pairagainstuserresult.save();
}
}

return res.status(200).json({
success: true,
message: "User Reserves against pair Added Successfully.",
Expand Down Expand Up @@ -790,7 +829,6 @@ router.route("/geteventsdata").post(async function (req, res, next) {
message: "There is no pair against this user to remove reserves.",
});
} else {

let data = await allcontractsDataModel.findOne({
packageHash: pairagainstuserresult.pair,
});
Expand All @@ -807,13 +845,46 @@ router.route("/geteventsdata").post(async function (req, res, next) {
"Record deleted because this pair against user has zero liquidity.",
});
} else {
pairagainstuserresult.reserve0 = (
BigInt(pairagainstuserresult.reserve0) - BigInt(reserve0)
).toString();
pairagainstuserresult.reserve1 = (
BigInt(pairagainstuserresult.reserve1) - BigInt(reserve1)
).toString();
await pairagainstuserresult.save();
if (
BigInt(pairagainstuserresult.reserve0) >
BigInt(pairagainstuserresult.reserve1)
) {
if (BigInt(reserve0) > BigInt(reserve1)) {
pairagainstuserresult.reserve0 = (
BigInt(pairagainstuserresult.reserve0) - BigInt(reserve0)
).toString();
pairagainstuserresult.reserve1 = (
BigInt(pairagainstuserresult.reserve1) - BigInt(reserve1)
).toString();
await pairagainstuserresult.save();
} else {
pairagainstuserresult.reserve0 = (
BigInt(pairagainstuserresult.reserve0) - BigInt(reserve1)
).toString();
pairagainstuserresult.reserve1 = (
BigInt(pairagainstuserresult.reserve1) - BigInt(reserve0)
).toString();
await pairagainstuserresult.save();
}
} else {
if (BigInt(reserve1) > BigInt(reserve0)) {
pairagainstuserresult.reserve0 = (
BigInt(pairagainstuserresult.reserve0) - BigInt(reserve0)
).toString();
pairagainstuserresult.reserve1 = (
BigInt(pairagainstuserresult.reserve1) - BigInt(reserve1)
).toString();
await pairagainstuserresult.save();
} else {
pairagainstuserresult.reserve0 = (
BigInt(pairagainstuserresult.reserve0) - BigInt(reserve1)
).toString();
pairagainstuserresult.reserve1 = (
BigInt(pairagainstuserresult.reserve1) - BigInt(reserve0)
).toString();
await pairagainstuserresult.save();
}
}
return res.status(200).json({
success: true,
message: "User Reserves against pair removed Successfully.",
Expand Down

0 comments on commit 52c1bf0

Please sign in to comment.