From 225eb9445ef5c9d9f680b1463c7b4494353eb7e6 Mon Sep 17 00:00:00 2001 From: Hammad-Mubeen Date: Tue, 4 Jan 2022 23:10:54 +0500 Subject: [PATCH] mint model liquidity endpoint added --- .env | 2 +- JsClients/PAIR/src/pair.ts | 9 +++++ JsClients/PAIR/test/installed.ts | 24 ++++++------ JsClients/ROUTER/test/installed.ts | 4 +- app.js | 2 + routes/mintroutes.js | 61 ++++++++++++++++++++++++++++++ 6 files changed, 87 insertions(+), 15 deletions(-) create mode 100644 routes/mintroutes.js diff --git a/.env b/.env index d8323f1b..ddcd3c5a 100644 --- a/.env +++ b/.env @@ -7,7 +7,7 @@ FACTORY_CONTRACT=E52D527b3E7d9818cEDb6484e0e51ED3550505465C454e4Bd5e95d9418f3f93 FACTORY_CONTRACT_PACKAGE=8589bE2588adb1240B8D6C470b4F2DF05cAa0bcb737962D77E3B628E9960Db2a WCSPR=d540e0435C6Be6E7f359e132a99566d8da9d4aDc6bF19254072F32cc62A922bB LIBRARY=e9E973B4c2D228d50311e696b0aedDEd80313F474a668E56c8Db31af0951a83c -PAIR_CONTRACT=27982d94c019D7E51c43C5aA60b771f458DcEddC7CEFFcc6d120f62B7321a610 +PAIR_CONTRACT=9c2AA298dc8f7bc10A7E57d005ED0A4C97597c963368246C51671c0794A48707 PAIR_CONTRACT_PACKAGE=4ed480e4d592852b515DeBDF7Af1301106F18649a314260A66DC29db743BCb1E CALLEE_CONTRACT=fbfeda8b97f056f526f20c2fc2b486d9bdbfb3e46b9a164527e57c0c86e68612 TOKEN0_CONTRACT=d540e0435C6Be6E7f359e132a99566d8da9d4aDc6bF19254072F32cc62A922bB diff --git a/JsClients/PAIR/src/pair.ts b/JsClients/PAIR/src/pair.ts index ac40f085..986b7916 100644 --- a/JsClients/PAIR/src/pair.ts +++ b/JsClients/PAIR/src/pair.ts @@ -183,6 +183,15 @@ class PAIRClient { ); return result.value(); } + + public async liquidity() { + const result = await contractSimpleGetter( + this.nodeAddress, + this.contractHash, + ["liquidity"] + ); + return result.value(); + } public async symbol() { const result = await contractSimpleGetter( diff --git a/JsClients/PAIR/test/installed.ts b/JsClients/PAIR/test/installed.ts index 37a310cd..492fae9f 100644 --- a/JsClients/PAIR/test/installed.ts +++ b/JsClients/PAIR/test/installed.ts @@ -67,27 +67,27 @@ function splitdata(data:string) const test = async () => { - await sleep(5 * 1000); + // await sleep(5 * 1000); - let accountInfo = await utils.getAccountInfo(NODE_ADDRESS!, KEYS.publicKey); + // let accountInfo = await utils.getAccountInfo(NODE_ADDRESS!, KEYS.publicKey); - console.log(`... Account Info: `); - console.log(JSON.stringify(accountInfo, null, 2)); + // console.log(`... Account Info: `); + // console.log(JSON.stringify(accountInfo, null, 2)); - const contractHash = await utils.getAccountNamedKeyValue( - accountInfo, - `${PAIR_CONTRACT_NAME!}_contract_hash` - ); + // const contractHash = await utils.getAccountNamedKeyValue( + // accountInfo, + // `${PAIR_CONTRACT_NAME!}_contract_hash` + // ); - console.log(`... Contract Hash: ${contractHash}`); + // console.log(`... Contract Hash: ${contractHash}`); // We don't need hash- prefix so i'm removing it //await pair.setContractHash(contractHash.slice(5)); await pair.setContractHash(PAIR_CONTRACT!); - + console.log("... Contract Hash:", PAIR_CONTRACT!); //name - // const name = await pair.name(); - // console.log(`... Contract name: ${name}`); + const liquidity = await pair.liquidity(); + console.log(`... Liquidity: ${liquidity}`); // //symbol // const symbol = await pair.symbol(); diff --git a/JsClients/ROUTER/test/installed.ts b/JsClients/ROUTER/test/installed.ts index f549b149..bf56c0d6 100644 --- a/JsClients/ROUTER/test/installed.ts +++ b/JsClients/ROUTER/test/installed.ts @@ -485,7 +485,7 @@ const test = async () => { //add_liquidity_cspr(uniswapRouter); // Test remove_liquidity - // remove_liquidity(uniswapRouter); + remove_liquidity(uniswapRouter); // Test remove_liquidity_cspr //remove_liquidity_cspr(uniswapRouter); @@ -497,7 +497,7 @@ const test = async () => { //remove_liquidity_cspr_with_permit(uniswapRouter); // Test swap_exact_tokens_for_tokens - swap_exact_tokens_for_tokens(uniswapRouter); + //swap_exact_tokens_for_tokens(uniswapRouter); // Test swap_tokens_for_exact_tokens //swap_tokens_for_exact_tokens(uniswapRouter); diff --git a/app.js b/app.js index ca25e6b2..79eee9f8 100644 --- a/app.js +++ b/app.js @@ -14,6 +14,7 @@ var tokensListRouter = require('./routes/tokenslist'); var pairsListRouter = require('./routes/pairslist'); var deploypairRouter = require('./routes/deploypair'); var swapRouter = require('./routes/swaproutes'); +var mintRouter = require('./routes/mintroutes'); var coinsmarketcapapiRouter = require('./routes/coinsmarketcapapi'); // view engine setup @@ -74,6 +75,7 @@ app.use('/', tokensListRouter); app.use('/', deploypairRouter); app.use('/', pairsListRouter); app.use('/', swapRouter); +app.use('/', mintRouter); app.use('/', coinsmarketcapapiRouter); app.use('/graphql', graphqlHTTP({ diff --git a/routes/mintroutes.js b/routes/mintroutes.js new file mode 100644 index 00000000..59831079 --- /dev/null +++ b/routes/mintroutes.js @@ -0,0 +1,61 @@ +require('dotenv').config() +var express = require('express'); +var router = express.Router(); +var mintModel=require('../models/mint'); + +router.route("/liquidityagainstuserandpair").post(async function (req, res, next) { + try { + + if (!req.body.to) { + return res.status(400).json({ + success: false, + message: "to not found in request body", + }); + } + + if (!req.body.pairid) { + return res.status(400).json({ + success: false, + message: "pairid not found in request body", + }); + } + var mintresult= await mintModel.find({to:req.body.to}); + + if(mintresult.length==0) + { + return res.status(400).json({ + success: false, + message: "There is no liquidity found in the database against this user.", + }); + } + else + { + let liquidity=0; + for(var i=0;i