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

Commit

Permalink
removereserves function updated
Browse files Browse the repository at this point in the history
  • Loading branch information
Hammad-Mubeen committed Apr 14, 2022
1 parent 7aaf5d7 commit f011f01
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 46 deletions.
66 changes: 33 additions & 33 deletions JsClients/ERC20/src/erc20.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
// });

Expand All @@ -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,
Expand Down
38 changes: 26 additions & 12 deletions JsClients/ERC20/test/installed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand All @@ -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
Expand All @@ -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!);
Expand Down
7 changes: 6 additions & 1 deletion routes/listenerroutes.js
Original file line number Diff line number Diff line change
Expand Up @@ -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") {
Expand Down

0 comments on commit f011f01

Please sign in to comment.