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

Commit

Permalink
mint model liquidity endpoint added
Browse files Browse the repository at this point in the history
  • Loading branch information
Hammad-Mubeen committed Jan 4, 2022
1 parent fda3385 commit 225eb94
Show file tree
Hide file tree
Showing 6 changed files with 87 additions and 15 deletions.
2 changes: 1 addition & 1 deletion .env
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
9 changes: 9 additions & 0 deletions JsClients/PAIR/src/pair.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
24 changes: 12 additions & 12 deletions JsClients/PAIR/test/installed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
4 changes: 2 additions & 2 deletions JsClients/ROUTER/test/installed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);
Expand Down
2 changes: 2 additions & 0 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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({
Expand Down
61 changes: 61 additions & 0 deletions routes/mintroutes.js
Original file line number Diff line number Diff line change
@@ -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<mintresult.length;i++)
{
if(req.body.pairid==mintresult[i].pair.id)
{
liquidity=liquidity+mintresult[i].liquidity;
}
if(i== (mintresult.length-1))
{
return res.status(200).json({
success: true,
message: "Liquidity has been found against this user against passed pair ",
liquidity:liquidity
});
}
}

}

} catch (error) {
console.log("error (try-catch) : " + error);
return res.status(500).json({
success: false,
err: error,
});
}
});

module.exports = router;

0 comments on commit 225eb94

Please sign in to comment.