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

Commit

Permalink
listener removed from router, listener, webhook and addpaircontractan…
Browse files Browse the repository at this point in the history
…dpackagehash code added
  • Loading branch information
Hammad-Mubeen committed Dec 14, 2021
1 parent 822be53 commit 2b054fe
Show file tree
Hide file tree
Showing 32 changed files with 671 additions and 1,767 deletions.
34 changes: 17 additions & 17 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@ NODE_MODE=deployed
DATABASE_URL_LOCAL=mongodb://localhost:27017/V2-graphQL
DATABASE_URL_ONLINE=mongodb+srv://admin:[email protected]/V2-graphQL-backend-demo?retryWrites=true&w=majority

FACTORY_CONTRACT=46505F2A814CC8Ee77E963a9dB101bEE4C9f96b47acAD65eE1084588b3e8e822
PAIR_CONTRACT=83c4d036f0912794cfb5896210298E6E9F228BE41626ddcf74583D16a26D7eD6
PAIR_CONTRACT_PACKAGE=984C671dF3c19563B760AF45586e913ab3C3C649BD8AFddbfd60807325803EAD
FACTORY_CONTRACT=BE48B5C9cfb0901A57db92fCB1b97d31Bfe536439efdC54a94f4C8bd1508Fc3C
PAIR_CONTRACT=Cfc208B9cd2fb35918D621D4002e378579382131d9D3011ff5A47aF36e603b2F
PAIR_CONTRACT_PACKAGE=1A89d4cDC6735c6c68D206b1C6c5c5c62ED96954F893A028Fa33E54C556B99AB
CALLEE_CONTRACT=fbfeda8b97f056f526f20c2fc2b486d9bdbfb3e46b9a164527e57c0c86e68612
TOKEN0_CONTRACT=7387033a0A3619caf217d8dF5E78D0814Fe6e3fa5Bd5DCfCe98C201851a97725
TOKEN0_CONTRACT_PACKAGE=03356D719373cB3E5A83c10548fED58919E7B4AFF23C7449d97b17e89d7D8727
TOKEN1_CONTRACT=f2dF436817e881ca2D9e945FD62680C546591A6ecb4E3b9Ec05E6e4BC2385B23
TOKEN1_CONTRACT_PACKAGE=6c2Fe8b6728Ce1C0320bF92867236e9d94aC41FD6997492B25422e4baa0E3c3f
TOKEN0_CONTRACT=E3F80775fddda7872185705BAAcc07aae66cFa5a07D5445D64D0C01642428D2d
TOKEN0_CONTRACT_PACKAGE=De0Ea05d65072DE515d6400f3Cf0FD2169A45938902C56B109BBAe62c4677955
TOKEN1_CONTRACT=f3c553Bed5D57B87FB1e7fDe02eC2a0355d64c0faD2fE872cB6DcC115197c1fe
TOKEN1_CONTRACT_PACKAGE=555282981d63c7fD7b66A4cDd747Ee30f9cdfC024b3bd2d918314e8b9A25b25C

GRAPHQL=http://localhost:3000/graphql
CHAIN_NAME=casper-test
NODE_ADDRESS=http://65.21.237.153:7777/rpc
EVENT_STREAM_ADDRESS=http://65.21.237.153:9999/events/main
NODE_ADDRESS=http://159.65.118.250:7777/rpc
EVENT_STREAM_ADDRESS=http://159.65.118.250:9999/events/main
RECEIVER_ACCOUNT_ONE=017e82abcc9539a01cfd9d63ae8c9c8b3a752a6f75ba1ab148714eea03e9be69a7

ERC20_WASM_PATH=JsClients/ERC20/wasm/erc20-token.wasm
Expand Down Expand Up @@ -43,7 +43,7 @@ FACTORY_CONTRACT_NAME=Factory

ERC20_INSTALL_PAYMENT_AMOUNT=200000000000
FACTORY_INSTALL_PAYMENT_AMOUNT=110000000000
PAIR_INSTALL_PAYMENT_AMOUNT=350000000000
PAIR_INSTALL_PAYMENT_AMOUNT=250000000000

MINT_PAYMENT_AMOUNT=5000000000
MINT_AMOUNT=2000
Expand Down Expand Up @@ -80,13 +80,13 @@ TOKEN_NAME=uniswap-router
TOKEN_SYMBOL=DRAG
TOKEN_META=origin fire,lifetime infinite

FACTORY=46505F2A814CC8Ee77E963a9dB101bEE4C9f96b47acAD65eE1084588b3e8e822
FACTORY=BE48B5C9cfb0901A57db92fCB1b97d31Bfe536439efdC54a94f4C8bd1508Fc3C
WCSPR=bA8f6a73B6D548E2CAe2d572aA2F824BC46A3C06a3BBA10e3d12B015931D3f85
LIBRARY=e0Dae7571C3dc5C957a36422c56BA0ccb8AECEC833F35e32874b75A8Ea8Ac4Db
CONTRACT_NAME=UniSwapRouter

CONTRACT_HASH=58e35630F1ef3797C28dc93a8e6Fb3F5980154e4793ee142D47eE95Cd48Feb62
PACKAGE_HASH=3b401aAfC1CCd3707DEaB6B39a3Bb42670487130c9EAB0b5BaCb2248900A88CA
CONTRACT_HASH=10c1405f84E629D0678620BaFCbaf0EDdE598e8717007B33A401458224c46dE7
PACKAGE_HASH=C8B976d8d1e122B1baEc32dd06c9DAA89f5277C1eB11ADd2414a23a273741258
INSTALL_PAYMENT_AMOUNT=200000000000
MINT_ONE_PAYMENT_AMOUNT=2000000000
MINT_COPIES_PAYMENT_AMOUNT=100000000000
Expand All @@ -97,12 +97,12 @@ MINT_COPIES_COUNT=20
MINT_MANY_META_SIZE=5
MINT_MANY_META_COUNT=5

TO = 7387033a0A3619caf217d8dF5E78D0814Fe6e3fa5Bd5DCfCe98C201851a97725
DEADLINE = 1699140435324
TO = E3F80775fddda7872185705BAAcc07aae66cFa5a07D5445D64D0C01642428D2d
DEADLINE = 1639403428465
# add_liquidity

TOKEN_A = 7387033a0A3619caf217d8dF5E78D0814Fe6e3fa5Bd5DCfCe98C201851a97725
TOKEN_B = f2dF436817e881ca2D9e945FD62680C546591A6ecb4E3b9Ec05E6e4BC2385B23
TOKEN_A = E3F80775fddda7872185705BAAcc07aae66cFa5a07D5445D64D0C01642428D2d
TOKEN_B = f3c553Bed5D57B87FB1e7fDe02eC2a0355d64c0faD2fE872cB6DcC115197c1fe
AMOUNT_A_DESIRED = 500
AMOUNT_B_DESIRED = 600
AMOUNT_A_MIN = 250
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-----
MCowBQYDK2VwAyEA+Gwj5LQ3PmnfmVjkxFcmZnD6FktIUMI0JRu823ZRpnE=
MCowBQYDK2VwAyEAs0KvzrC+3c3b48+M5hiTCBzTc1HVJZtYE+7n/r9r+dU=
-----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 @@
01f86c23e4b4373e69df9958e4c457266670fa164b4850c234251bbcdb7651a671
01b342afceb0beddcddbe3cf8ce61893081cd37351d5259b5813eee7febf6bf9d5
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-----
MC4CAQAwBQYDK2VwBCIEILXBMhV7E1w2R3bgTAbiYmAju2yKUF5ZUuS2I0moHO2I
MC4CAQAwBQYDK2VwBCIEIEAEVlLDzYh9hwBwLu3H2fsQVUrEZKJs+UblNZ9N0WhS
-----END PRIVATE KEY-----
171 changes: 104 additions & 67 deletions JsClients/ERC20/test/installed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,8 @@ import { config } from "dotenv";
config();
import { ERC20Client ,utils, constants} from "../src";
import { sleep, getDeploy } from "./utils";
//import { ERC20Events } from '../src/constants';
import { request } from 'graphql-request';

import {
CLValueBuilder,
Keys,
Expand Down Expand Up @@ -38,7 +39,8 @@ const {
AMOUNT_A_DESIRED,
AMOUNT_B_DESIRED,
MASTER_KEY_PAIR_PATH,
PAIR_CONTRACT_PACKAGE
PAIR_CONTRACT_PACKAGE,
GRAPHQL
} = process.env;


Expand All @@ -52,61 +54,95 @@ const ROUTERKEYS = Keys.Ed25519.parseKeyFiles(
`${MASTER_KEY_PAIR_PATH}/secret_key.pem`
);

function splitdata(data:string)
{
var temp=data.split('(');
var result=temp[1].split(')');
return result[0];
}

const erc20 = new ERC20Client(
NODE_ADDRESS!,
CHAIN_NAME!,
EVENT_STREAM_ADDRESS!
);

const test = async () => {

const listener = erc20.onEvent(
[
ERC20Events.Approval,
ERC20Events.Transfer
],
async (eventName, deploy, result) => {
if (deploy.success) {
console.log(`Successfull deploy of: ${eventName}, deployHash: ${deploy.deployHash}`);
const [timestamp,gasPrice,block_hash]= await getDeploy(NODE_ADDRESS!, deploy.deployHash);
console.log("... Deployhash: ", deploy.deployHash);
console.log("... Timestamp: ", timestamp);
//console.log("... GasPrice: ", gasPrice);
console.log("... Block hash: ", block_hash);

let newData = JSON.parse(JSON.stringify(result.value()));

console.log(eventName+ " Event result: ");
console.log(newData[0][0].data + " = " + newData[0][1].data);
console.log(newData[1][0].data + " = " + newData[1][1].data);
console.log(newData[2][0].data + " = " + newData[2][1].data);
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}`);
}
}
);
console.log("listener: ",listener);

await sleep(5 * 1000);

let accountInfo = await utils.getAccountInfo(NODE_ADDRESS!, KEYS.publicKey);

console.log(`... Account Info: `);
console.log(JSON.stringify(accountInfo, null, 2));

const contractHash = await utils.getAccountNamedKeyValue(
accountInfo,
`${ERC20_CONTRACT_NAME!}_contract_hash`
);

console.log(`... Contract Hash: ${contractHash}`);
// const listener = erc20.onEvent(
// [
// ERC20Events.Approval,
// ERC20Events.Transfer
// ],
// async (eventName, deploy, result) => {
// if (deploy.success) {
// console.log(`Successfull deploy of: ${eventName}, deployHash: ${deploy.deployHash}`);
// const [timestamp,gasPrice,block_hash]= await getDeploy(NODE_ADDRESS!, deploy.deployHash);
// console.log("... Deployhash: ", deploy.deployHash);
// console.log("... Timestamp: ", timestamp);
// //console.log("... GasPrice: ", gasPrice);
// console.log("... Block hash: ", block_hash);

// let newData = JSON.parse(JSON.stringify(result.value()));

// if(eventName=="approve")
// {
// console.log(eventName+ " Event result: ");
// console.log(newData[0][0].data + " = " + newData[0][1].data);
// console.log(newData[1][0].data + " = " + newData[1][1].data);
// console.log(newData[2][0].data + " = " + newData[2][1].data);
// console.log(newData[3][0].data + " = " + newData[3][1].data);
// console.log(newData[4][0].data + " = " + newData[4][1].data);
// }
// else if(eventName=="erc20_transfer")
// {
// console.log(eventName+ " Event result: ");
// console.log(newData[0][0].data + " = " + newData[0][1].data);
// console.log(newData[1][0].data + " = " + newData[1][1].data);

// console.log(newData[2][0].data + " = " + newData[2][1].data);
// console.log(newData[3][0].data + " = " + newData[3][1].data);
// console.log(newData[4][0].data + " = " + newData[4][1].data);

// var flag=0;
// var temp=(newData[3][1].data).split('(');
// console.log("temp[0]: ",temp[0]);
// if(temp[0] == "Key::Account(")
// {
// flag=1;
// }
// var from=splitdata(newData[2][1].data);
// var to=splitdata(newData[3][1].data);
// var value=parseInt(newData[4][1].data);

// console.log("from: ", from);
// console.log("to: ", to);
// console.log("value: ",value);

// if(flag==0)
// {
// request(GRAPHQL!,
// `mutation handleTransfer( $from: String!, $to: String!, $value: Int!, $pairAddress: String!, $deployHash: String!, $timeStamp: String!, $blockHash: String!){
// handleTransfer( from: $from, to: $to, value: $value, pairAddress: $pairAddress, deployHash: $deployHash, timeStamp: $timeStamp, blockHash: $blockHash) {
// result
// }

// }`,
// {from:from, to: to, value: value, pairAddress: to, deployHash:deploy.deployHash,timeStamp:timestamp.toString(), blockHash:block_hash})
// .then(data => console.log(data))
// .catch(error => console.error(error));
// }

// }

// } else {
// console.log(`Failed deploy of ${eventName}, deployHash: ${deploy.deployHash}`);
// console.log(`Error: ${deploy.error}`);
// }
// }
// );
// console.log("listener: ",listener);

// // We don't need hash- prefix so i'm removing it
//await erc20.setContractHash(contractHash.slice(5));
await erc20.setContractHash(TOKEN1_CONTRACT!);

// // //name
Expand Down Expand Up @@ -139,18 +175,18 @@ const test = async () => {
// // // console.log(`... Allowance: ${allowance}`);

//mint
// const mintDeployHash = await erc20.mint(
// ROUTERKEYS,
// ROUTERKEYS.publicKey,
// MINT_AMOUNT!,
// MINT_PAYMENT_AMOUNT!
// );
// console.log("... Mint deploy hash: ", mintDeployHash);
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.");
await getDeploy(NODE_ADDRESS!, mintDeployHash);
console.log("... Token minted successfully.");

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

Expand All @@ -171,16 +207,16 @@ const test = async () => {
// // console.log(`... Total supply: ${totalSupply}`);

//approve
const approveDeployHash = await erc20.approve(
ROUTERKEYS,
PACKAGE_HASH!,
AMOUNT_B_DESIRED!,
APPROVE_PAYMENT_AMOUNT!
);
console.log("... Approve deploy hash: ", approveDeployHash);
// const approveDeployHash = await erc20.approve(
// ROUTERKEYS,
// PACKAGE_HASH!,
// AMOUNT_A_DESIRED!,
// APPROVE_PAYMENT_AMOUNT!
// );
// console.log("... Approve deploy hash: ", approveDeployHash);

await getDeploy(NODE_ADDRESS!, approveDeployHash);
console.log("... Token approved successfully");
// await getDeploy(NODE_ADDRESS!, approveDeployHash);
// console.log("... Token approved successfully");

// // //transfer
// // const transferDeployHash = await erc20.transfer(
Expand Down Expand Up @@ -209,6 +245,7 @@ const test = async () => {

};


test();

export const getName = async (contractHash:string) => {
Expand Down
2 changes: 1 addition & 1 deletion JsClients/FACTORY/keys/public_key.pem
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
-----BEGIN PUBLIC KEY-----
MCowBQYDK2VwAyEATkKacKRbXO7m8cL0EqIk1eo8YV9QRtdhhKIATP8NkEY=
MCowBQYDK2VwAyEA4Uucv/tdlBPn+RuHu0L5ihGGJlO2MwC85wbbjmCC1so=
-----END PUBLIC KEY-----
2 changes: 1 addition & 1 deletion JsClients/FACTORY/keys/public_key_hex
Original file line number Diff line number Diff line change
@@ -1 +1 @@
014e429a70a45b5ceee6f1c2f412a224d5ea3c615f5046d76184a2004cff0d9046
01e14b9cbffb5d9413e7f91b87bb42f98a11862653b63300bce706db8e6082d6ca
2 changes: 1 addition & 1 deletion JsClients/FACTORY/keys/secret_key.pem
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
-----BEGIN PRIVATE KEY-----
MC4CAQAwBQYDK2VwBCIEIN9+mOCy+hYO+yItDcRuHawnIUKq+HvOml4qExk8ITfT
MC4CAQAwBQYDK2VwBCIEIBptGPvy3geNeR1+Ses6LnNP9+dYYRtSy9I2jnr2N+V7
-----END PRIVATE KEY-----
2 changes: 1 addition & 1 deletion JsClients/PAIR/keys/public_key.pem
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
-----BEGIN PUBLIC KEY-----
MCowBQYDK2VwAyEAMfyQQNEYSp6VQcd9N2GpRmGcx+1+Wl6myTehyxbCLP4=
MCowBQYDK2VwAyEAWCo4o5U2zNgRQan9mjlKj0AfjdVcyN1tigR0wnRMPTs=
-----END PUBLIC KEY-----
2 changes: 1 addition & 1 deletion JsClients/PAIR/keys/public_key_hex
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0131fc9040d1184a9e9541c77d3761a946619cc7ed7e5a5ea6c937a1cb16c22cfe
01582a38a39536ccd81141a9fd9a394a8f401f8dd55cc8dd6d8a0474c2744c3d3b
2 changes: 1 addition & 1 deletion JsClients/PAIR/keys/secret_key.pem
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
-----BEGIN PRIVATE KEY-----
MC4CAQAwBQYDK2VwBCIEIO4zMC4Rx+Mnh5sCLc0E5jhAhLZDPmHN1JDC0NGTD8ti
MC4CAQAwBQYDK2VwBCIEIFCrU4+IUFtE+Clin5T6gCH05T11RteCOhbzNRzezBl9
-----END PRIVATE KEY-----
1 change: 1 addition & 0 deletions JsClients/PAIR/src/constants.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
export enum PAIREvents {
Approval = 'approve',
Transfer = 'transfer',
Erc20Transfer = 'erc20_transfer',
Mint = 'mint',
Burn = 'burn',
Sync = 'sync',
Expand Down
Loading

0 comments on commit 2b054fe

Please sign in to comment.