From f011f01ecad8b4dc7d0735063f035f936c802f72 Mon Sep 17 00:00:00 2001 From: Hammad-Mubeen Date: Thu, 14 Apr 2022 22:10:39 +0500 Subject: [PATCH] removereserves function updated --- JsClients/ERC20/src/erc20.ts | 66 +++++++++++++++---------------- JsClients/ERC20/test/installed.ts | 38 ++++++++++++------ routes/listenerroutes.js | 7 +++- 3 files changed, 65 insertions(+), 46 deletions(-) diff --git a/JsClients/ERC20/src/erc20.ts b/JsClients/ERC20/src/erc20.ts index 42d2f22d..b1fa9864 100644 --- a/JsClients/ERC20/src/erc20.ts +++ b/JsClients/ERC20/src/erc20.ts @@ -328,44 +328,15 @@ class ERC20Client { throw Error("Invalid Deploy"); } } - public async mint( - keys: Keys.AsymmetricKey, - to: RecipientType, - amount: string, - paymentAmount: string - ) { - - const runtimeArgs = RuntimeArgs.fromMap({ - to:utils.createRecipientAddress(to), - amount: CLValueBuilder.u256(amount) - }); - - const deployHash = await contractCall({ - chainName: this.chainName, - contractHash: this.contractHash, - entryPoint: "mint", - keys, - nodeAddress: this.nodeAddress, - paymentAmount, - runtimeArgs, - }); - - if (deployHash !== null) { - - return deployHash; - } else { - throw Error("Invalid Deploy"); - } - } // public async mint( // keys: Keys.AsymmetricKey, - // to: string, + // to: RecipientType, // amount: string, // paymentAmount: string // ) { - // const tobytearray = new CLByteArray(Uint8Array.from(Buffer.from(to, 'hex'))); + // const runtimeArgs = RuntimeArgs.fromMap({ - // to: CLValueBuilder.key(tobytearray), + // to:utils.createRecipientAddress(to), // amount: CLValueBuilder.u256(amount) // }); @@ -380,12 +351,41 @@ class ERC20Client { // }); // if (deployHash !== null) { - + // return deployHash; // } else { // throw Error("Invalid Deploy"); // } // } + public async mint( + keys: Keys.AsymmetricKey, + to: string, + amount: string, + paymentAmount: string + ) { + const tobytearray = new CLByteArray(Uint8Array.from(Buffer.from(to, 'hex'))); + const runtimeArgs = RuntimeArgs.fromMap({ + to: CLValueBuilder.key(tobytearray), + amount: CLValueBuilder.u256(amount) + }); + + const deployHash = await contractCall({ + chainName: this.chainName, + contractHash: this.contractHash, + entryPoint: "mint", + keys, + nodeAddress: this.nodeAddress, + paymentAmount, + runtimeArgs, + }); + + if (deployHash !== null) { + + return deployHash; + } else { + throw Error("Invalid Deploy"); + } + } public async burn( keys: Keys.AsymmetricKey, from: RecipientType, diff --git a/JsClients/ERC20/test/installed.ts b/JsClients/ERC20/test/installed.ts index 3ff1a362..1ec0da12 100644 --- a/JsClients/ERC20/test/installed.ts +++ b/JsClients/ERC20/test/installed.ts @@ -70,7 +70,8 @@ const erc20 = new ERC20Client( const test = async () => { - await erc20.setContractHash(TOKEN0_CONTRACT!); + await erc20.setContractHash(TOKEN1_CONTRACT!); + console.log("contract:"+ TOKEN1_CONTRACT!); //getTotalSupply(TOKEN1_CONTRACT!); // // //name // // const name = await erc20.name(); @@ -89,7 +90,8 @@ const test = async () => { // // console.log(`... Total supply: ${totalSupply}`); // // // //balanceof - // let balance = await erc20.balanceOf("7b217a09296d5ce360847a7d20f623476157c5f022333c4e988a464035cadd80"); + // console.log("user: 0d72ccd15e717fde4afc91fab70cb20e9986da52c670976386efc91b375f52a8"); + // let balance = await erc20.balanceOf("0d72ccd15e717fde4afc91fab70cb20e9986da52c670976386efc91b375f52a8"); // console.log(`... Balance: ${balance}`); // // //nonce @@ -100,17 +102,29 @@ const test = async () => { //let allowance = await erc20.allowance(KEYS.publicKey,KEYS.publicKey); // console.log(`... Allowance: ${allowance}`); + // //mint + // const mintDeployHash = await erc20.mint( + // ROUTERKEYS, + // ROUTERKEYS.publicKey, + // MINT_AMOUNT!, + // MINT_PAYMENT_AMOUNT! + // ); + // console.log("... Mint deploy hash: ", mintDeployHash); + + // await getDeploy(NODE_ADDRESS!, mintDeployHash); + // console.log("... Token minted successfully."); + //mint - const mintDeployHash = await erc20.mint( - ROUTERKEYS, - ROUTERKEYS.publicKey, - 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, + // "0d72ccd15e717fde4afc91fab70cb20e9986da52c670976386efc91b375f52a8", + // 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!); diff --git a/routes/listenerroutes.js b/routes/listenerroutes.js index f041702e..1bfddcba 100644 --- a/routes/listenerroutes.js +++ b/routes/listenerroutes.js @@ -790,8 +790,13 @@ 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, + }); + let liquidity = await paircontract.balanceOf( - pairagainstuserresult.pair, + data.contractHash, pairagainstuserresult.id.toLowerCase() ); if (liquidity == "0") {