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

Commit

Permalink
listener work added to backend , and made to be work generic...
Browse files Browse the repository at this point in the history
  • Loading branch information
Hammad-Mubeen committed Dec 3, 2021
1 parent f66337f commit b499459
Show file tree
Hide file tree
Showing 26 changed files with 948 additions and 311 deletions.
1 change: 1 addition & 0 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ PAIR_CONTRACT_PACKAGE=106dbf09aac7eb0ed2d41f4026fe2d8cd5f492b17c5050db9c519591c6
CALLEE_CONTRACT=fbfeda8b97f056f526f20c2fc2b486d9bdbfb3e46b9a164527e57c0c86e68612
TOKEN0_CONTRACT=f5b45ffd5273c94befa572ca4b3f05a57892611aa7c668a021eed2be93e9b76e
TOKEN1_CONTRACT=c5afe9ac0deddaf3090603b1cc1b71b9c030218ff97f7c4067a48402803fea16
EXTERNAL_CONTRACT=0A01Dd10Ef3562112818F91af977f10EA12BB4417AdFd9aF0ff4f3824862E3CC

GRAPHQL=http://localhost:3000/graphql
CHAIN_NAME=casper-test
Expand Down
2 changes: 1 addition & 1 deletion JsClients/ERC20/keys/public_key.pem
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
-----BEGIN PUBLIC KEY-----
MCowBQYDK2VwAyEAFbfKrhxmPOuj4Fdvws91dyBK41iFwThXga97hwwnyvI=
MCowBQYDK2VwAyEAmYl/IwN4hACVTqvQyFqUb6Xz3ewXk8Kkvq+pnmMtLLw=
-----END PUBLIC KEY-----
2 changes: 1 addition & 1 deletion JsClients/ERC20/keys/public_key_hex
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0115b7caae1c663ceba3e0576fc2cf7577204ae35885c1385781af7b870c27caf2
0199897f2303788400954eabd0c85a946fa5f3ddec1793c2a4beafa99e632d2cbc
2 changes: 1 addition & 1 deletion JsClients/ERC20/keys/secret_key.pem
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
-----BEGIN PRIVATE KEY-----
MC4CAQAwBQYDK2VwBCIEICBBb2iWScPvTzvMkukUC1fbeFbXM2N2jqEBz+Da6i6H
MC4CAQAwBQYDK2VwBCIEIHNb3AdH407fuI6D2jQSVh4xwPIl5V2RNr2hB5Ynd3ST
-----END PRIVATE KEY-----
1 change: 1 addition & 0 deletions JsClients/ERC20/src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ export enum ERC20Events {
Approval="approve",
Transfer="transfer"
}

6 changes: 4 additions & 2 deletions JsClients/ERC20/src/erc20.ts
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,9 @@ class ERC20Client {
const event = clValue.get(CLValueBuilder.string("event_type"));
if (
hash &&
hash.value() === this.contractPackageHash &&
// NOTE: Calling toLowerCase() because current JS-SDK doesn't support checksumed hashes and returns all lower case value
// Remove it after updating SDK
hash.value() === this.contractPackageHash.toLowerCase() &&
event &&
eventNames.includes(event.value())
) {
Expand Down Expand Up @@ -503,7 +505,7 @@ class ERC20Client {
};
}

private addPendingDeploy(deployType: ERC20Events, deployHash: string) {
public addPendingDeploy(deployType: ERC20Events, deployHash: string) {
this.pendingDeploys = [...this.pendingDeploys, { deployHash, deployType }];
}
}
Expand Down
197 changes: 98 additions & 99 deletions JsClients/ERC20/test/installed.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { config } from "dotenv";
config();
import { ERC20Client, utils, constants } from "../src";
import { ERC20Client ,utils, constants} from "../src";
import { sleep, getDeploy } from "./utils";

//import { ERC20Events } from '../src/constants';
import {
CLValueBuilder,
Keys,
Expand Down Expand Up @@ -31,6 +31,7 @@ const {
TRANSFER_FROM_AMOUNT,
TOKEN0_CONTRACT,
TOKEN1_CONTRACT,
EXTERNAL_CONTRACT,
PAIR_CONTRACT
} = process.env;

Expand All @@ -47,7 +48,7 @@ const erc20 = new ERC20Client(
);

const test = async () => {

const listener = erc20.onEvent(
[
ERC20Events.Approval,
Expand All @@ -71,7 +72,6 @@ const test = async () => {
console.log(newData[3][0].data + " = " + newData[3][1].data);
console.log(newData[4][0].data + " = " + newData[4][1].data);


} else {
console.log(`Failed deploy of ${eventName}, deployHash: ${deploy.deployHash}`);
console.log(`Error: ${deploy.error}`);
Expand All @@ -80,85 +80,85 @@ const test = async () => {
);
console.log("listener: ",listener);

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,
`${ERC20_CONTRACT_NAME!}_contract_hash`
);
// const contractHash = await utils.getAccountNamedKeyValue(
// accountInfo,
// `${ERC20_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 erc20.setContractHash(contractHash.slice(5));
await erc20.setContractHash(TOKEN0_CONTRACT!);

// //name
// const name = await erc20.name();
// console.log(`... Contract name: ${name}`);

// //symbol
// const symbol = await erc20.symbol();
// console.log(`... Contract symbol: ${symbol}`);

// //decimal
// const decimal = await erc20.decimal();
// console.log(`... Contract decimal: ${decimal}`);

// //totalsupply
// let totalSupply = await erc20.totalSupply();
// console.log(`... Total supply: ${totalSupply}`);

// // //balanceof
// let balance = await erc20.balanceOf(KEYS.publicKey);
// console.log(`... Balance of account ${KEYS.publicKey.toAccountHashStr()}`);
// console.log(`... Balance: ${balance}`);

// //nonce
// let nonce = await erc20.nonce(KEYS.publicKey);
// console.log(`... Nonce: ${nonce}`);

// // //allowance
// // let allowance = await erc20.allowance(KEYS.publicKey,KEYS.publicKey);
// // console.log(`... Allowance: ${allowance}`);

//mint
const mintDeployHash = await erc20.mint(
KEYS,
PAIR_CONTRACT!,
MINT_AMOUNT!,
MINT_PAYMENT_AMOUNT!
);
console.log("... Mint deploy hash: ", mintDeployHash);
// // // We don't need hash- prefix so i'm removing it
// // //await erc20.setContractHash(contractHash.slice(5));
// await erc20.setContractHash(EXTERNAL_CONTRACT!);

await getDeploy(NODE_ADDRESS!, mintDeployHash);

//balanceof
let balance = await erc20.balanceOfcontract(PAIR_CONTRACT!);
console.log(`... Balance: ${balance}`);
// // //name
// // const name = await erc20.name();
// // console.log(`... Contract name: ${name}`);

// //burn
// const burnDeployHash = await erc20.burn(
// KEYS,
// KEYS.publicKey,
// BURN_AMOUNT!,
// BURN_PAYMENT_AMOUNT!
// );
// console.log("... Burn deploy hash: ", burnDeployHash);
// // //symbol
// // const symbol = await erc20.symbol();
// // console.log(`... Contract symbol: ${symbol}`);

// // //decimal
// // const decimal = await erc20.decimal();
// // console.log(`... Contract decimal: ${decimal}`);

// // //totalsupply
// // let totalSupply = await erc20.totalSupply();
// // console.log(`... Total supply: ${totalSupply}`);

// await getDeploy(NODE_ADDRESS!, burnDeployHash);
// console.log("... Token burned successfully");
// // // //balanceof
// // let balance = await erc20.balanceOf(KEYS.publicKey);
// // console.log(`... Balance of account ${KEYS.publicKey.toAccountHashStr()}`);
// // console.log(`... Balance: ${balance}`);

// //totalsupply
// totalSupply = await erc20.totalSupply();
// console.log(`... Total supply: ${totalSupply}`);
// // //nonce
// // let nonce = await erc20.nonce(KEYS.publicKey);
// // console.log(`... Nonce: ${nonce}`);

// //approve
// // // //allowance
// // // let allowance = await erc20.allowance(KEYS.publicKey,KEYS.publicKey);
// // // console.log(`... Allowance: ${allowance}`);

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

// // await getDeploy(NODE_ADDRESS!, mintDeployHash);

// // //balanceof
// // let balance = await erc20.balanceOfcontract(PAIR_CONTRACT!);
// // console.log(`... Balance: ${balance}`);

// // //burn
// // const burnDeployHash = await erc20.burn(
// // KEYS,
// // KEYS.publicKey,
// // BURN_AMOUNT!,
// // BURN_PAYMENT_AMOUNT!
// // );
// // console.log("... Burn deploy hash: ", burnDeployHash);

// // await getDeploy(NODE_ADDRESS!, burnDeployHash);
// // console.log("... Token burned successfully");

// // //totalsupply
// // totalSupply = await erc20.totalSupply();
// // console.log(`... Total supply: ${totalSupply}`);

//approve
// const approveDeployHash = await erc20.approve(
// KEYS,
// KEYS.publicKey,
Expand All @@ -170,35 +170,34 @@ const test = async () => {
// await getDeploy(NODE_ADDRESS!, approveDeployHash);
// console.log("... Token approved successfully");

// //transfer
// const transferDeployHash = await erc20.transfer(
// KEYS,
// KEYS.publicKey,
// TRANSFER_AMOUNT!,
// TRANSFER_PAYMENT_AMOUNT!
// );
// console.log("... Transfer deploy hash: ", transferDeployHash);

// await getDeploy(NODE_ADDRESS!, transferDeployHash);
// console.log("... Token transfer successfully");

// //transfer_from
// const transferfromDeployHash = await erc20.transferFrom(
// KEYS,
// KEYS.publicKey,
// KEYS.publicKey,
// TRANSFER_FROM_AMOUNT!,
// TRANSFER_FROM_PAYMENT_AMOUNT!
// );
// console.log("... TransferFrom deploy hash: ", transferfromDeployHash);

// await getDeploy(NODE_ADDRESS!, transferfromDeployHash);
// console.log("... Token transfer successfully");
// // //transfer
// // const transferDeployHash = await erc20.transfer(
// // KEYS,
// // KEYS.publicKey,
// // TRANSFER_AMOUNT!,
// // TRANSFER_PAYMENT_AMOUNT!
// // );
// // console.log("... Transfer deploy hash: ", transferDeployHash);

// // await getDeploy(NODE_ADDRESS!, transferDeployHash);
// // console.log("... Token transfer successfully");

// // //transfer_from
// // const transferfromDeployHash = await erc20.transferFrom(
// // KEYS,
// // KEYS.publicKey,
// // KEYS.publicKey,
// // TRANSFER_FROM_AMOUNT!,
// // TRANSFER_FROM_PAYMENT_AMOUNT!
// // );
// // console.log("... TransferFrom deploy hash: ", transferfromDeployHash);

// // await getDeploy(NODE_ADDRESS!, transferfromDeployHash);
// // console.log("... Token transfer successfully");

};

//test();

//test();

export const getName = async (contractHash:string) => {

Expand Down
11 changes: 11 additions & 0 deletions JsClients/Events/src/constants.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
export enum Events {
PairCreated="pair_created",
Approval = 'approve',
Transfer = 'transfer',
Mint = 'mint',
Burn = 'burn',
Sync = 'sync',
Swap = 'swap'

}

Loading

0 comments on commit b499459

Please sign in to comment.