From 84053c64c6b854b8c4562d4e13289a02def4d59d Mon Sep 17 00:00:00 2001 From: Hammad-Mubeen Date: Mon, 30 May 2022 23:39:29 +0500 Subject: [PATCH] keys successfully removed and added to .gitignore now, to do deployment first create keys, fund them then add them to scripts ERC20, FACTORY, PAIR and ROUTER folders etherwise runn scripts command would throw errors. See all script commands from readme --- .env | 20 +- .gitignore | 8 +- .../erc20FunctionsForBackend/functions.ts | 98 +++++++ JsClients/ERC20/keys/public_key.pem | 3 - JsClients/ERC20/keys/public_key_hex | 1 - JsClients/ERC20/keys/secret_key.pem | 3 - JsClients/ERC20/scripts/installed.ts | 274 ------------------ JsClients/ERC20/src/constants.ts | 5 - JsClients/ERC20/src/erc20.ts | 181 +----------- JsClients/ERC20/src/index.ts | 4 +- JsClients/ERC20/src/types.d.ts | 2 - .../factoryFunctionsForBackend/functions.ts | 30 ++ JsClients/FACTORY/keys/public_key.pem | 3 - JsClients/FACTORY/keys/public_key_hex | 1 - JsClients/FACTORY/keys/secret_key.pem | 3 - JsClients/FACTORY/src/constants.ts | 3 - JsClients/FACTORY/src/factory.ts | 121 +------- JsClients/FACTORY/src/index.ts | 4 +- JsClients/FACTORY/src/types.d.ts | 1 - JsClients/PAIR/keys/public_key.pem | 3 - JsClients/PAIR/keys/public_key_hex | 1 - JsClients/PAIR/keys/secret_key.pem | 3 - .../PAIR/pairFunctionsForBackend/functions.ts | 77 +++++ JsClients/PAIR/src/constants.ts | 10 - JsClients/PAIR/src/index.ts | 4 +- JsClients/PAIR/src/pair.ts | 125 +------- JsClients/PAIR/src/types.d.ts | 1 - JsClients/ROUTER/keys/public_key.pem | 3 - JsClients/ROUTER/keys/public_key_hex | 1 - JsClients/ROUTER/keys/secret_key.pem | 3 - .../routerFunctionsForBackend/functions.ts | 44 +++ JsClients/ROUTER/src/constants.ts | 10 - JsClients/ROUTER/src/index.ts | 4 +- JsClients/ROUTER/src/types.d.ts | 2 - JsClients/ROUTER/src/uniswap-router-client.ts | 119 -------- .../ERC20/deploy/erc20Contract.ts | 10 +- .../ERC20/deploy/erc20ContractFunctions.ts | 160 ++++++++++ .../scripts => Scripts/ERC20/deploy}/utils.ts | 0 .../ERC20/wasm/erc20-token.wasm | Bin .../ERC20/wasm/purse-proxy.wasm | Bin .../FACTORY/deploy/factoryContract.ts | 8 +- .../deploy/factoryContractFunctions.ts | 85 +----- .../FACTORY/deploy}/utils.ts | 0 .../FACTORY/wasm/factory.wasm | Bin .../PAIR/deploy/pairContract.ts | 36 +-- .../PAIR/deploy/pairContractFunctions.ts | 132 +++------ .../scripts => Scripts/PAIR/deploy}/utils.ts | 0 .../PAIR/wasm/pair-token.wasm | Bin .../ROUTER/deploy/routerContract.ts | 13 +- .../ROUTER/deploy/routerContractFunctions.ts | 115 +++----- .../ROUTER/deploy}/utils.ts | 0 .../ROUTER/wasm/purse-proxy.wasm | Bin .../ROUTER/wasm/uniswap-v2-router.wasm | Bin graphql/dayUpdates.js | 5 +- graphql/helpers.js | 2 +- graphql/mutations.js | 46 ++- graphql/pricing.js | 16 +- package-lock.json | 145 ++++----- package.json | 16 +- readme.md | 47 ++- routes/deploypair.js | 2 +- routes/erc20routes.js | 2 +- routes/listenerroutes.js | 2 +- routes/pairroutes.js | 2 +- routes/readWasm.js | 4 +- routes/swaproutes.js | 2 +- 66 files changed, 700 insertions(+), 1325 deletions(-) create mode 100644 JsClients/ERC20/erc20FunctionsForBackend/functions.ts delete mode 100644 JsClients/ERC20/keys/public_key.pem delete mode 100644 JsClients/ERC20/keys/public_key_hex delete mode 100644 JsClients/ERC20/keys/secret_key.pem delete mode 100644 JsClients/ERC20/scripts/installed.ts delete mode 100644 JsClients/ERC20/src/constants.ts create mode 100644 JsClients/FACTORY/factoryFunctionsForBackend/functions.ts delete mode 100644 JsClients/FACTORY/keys/public_key.pem delete mode 100644 JsClients/FACTORY/keys/public_key_hex delete mode 100644 JsClients/FACTORY/keys/secret_key.pem delete mode 100644 JsClients/FACTORY/src/constants.ts delete mode 100644 JsClients/PAIR/keys/public_key.pem delete mode 100644 JsClients/PAIR/keys/public_key_hex delete mode 100644 JsClients/PAIR/keys/secret_key.pem create mode 100644 JsClients/PAIR/pairFunctionsForBackend/functions.ts delete mode 100644 JsClients/PAIR/src/constants.ts delete mode 100644 JsClients/ROUTER/keys/public_key.pem delete mode 100644 JsClients/ROUTER/keys/public_key_hex delete mode 100644 JsClients/ROUTER/keys/secret_key.pem create mode 100644 JsClients/ROUTER/routerFunctionsForBackend/functions.ts delete mode 100644 JsClients/ROUTER/src/constants.ts rename JsClients/ERC20/scripts/install.ts => Scripts/ERC20/deploy/erc20Contract.ts (90%) create mode 100644 Scripts/ERC20/deploy/erc20ContractFunctions.ts rename {JsClients/ERC20/scripts => Scripts/ERC20/deploy}/utils.ts (100%) rename {JsClients => Scripts}/ERC20/wasm/erc20-token.wasm (100%) mode change 100755 => 100644 rename {JsClients => Scripts}/ERC20/wasm/purse-proxy.wasm (100%) rename JsClients/FACTORY/scripts/install.ts => Scripts/FACTORY/deploy/factoryContract.ts (90%) rename JsClients/FACTORY/scripts/installed.ts => Scripts/FACTORY/deploy/factoryContractFunctions.ts (60%) rename {JsClients/FACTORY/scripts => Scripts/FACTORY/deploy}/utils.ts (100%) rename {JsClients => Scripts}/FACTORY/wasm/factory.wasm (100%) mode change 100755 => 100644 rename JsClients/PAIR/scripts/install.ts => Scripts/PAIR/deploy/pairContract.ts (69%) rename JsClients/PAIR/scripts/installed.ts => Scripts/PAIR/deploy/pairContractFunctions.ts (73%) rename {JsClients/PAIR/scripts => Scripts/PAIR/deploy}/utils.ts (100%) rename {JsClients => Scripts}/PAIR/wasm/pair-token.wasm (100%) mode change 100755 => 100644 rename JsClients/ROUTER/scripts/install.ts => Scripts/ROUTER/deploy/routerContract.ts (91%) rename JsClients/ROUTER/scripts/installed.ts => Scripts/ROUTER/deploy/routerContractFunctions.ts (79%) rename {JsClients/ROUTER/scripts => Scripts/ROUTER/deploy}/utils.ts (100%) rename {JsClients => Scripts}/ROUTER/wasm/purse-proxy.wasm (100%) rename {JsClients => Scripts}/ROUTER/wasm/uniswap-v2-router.wasm (100%) diff --git a/.env b/.env index e6021024..8c5bbad4 100644 --- a/.env +++ b/.env @@ -50,15 +50,15 @@ 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 -FACTORY_WASM_PATH=JsClients/FACTORY/wasm/factory.wasm -PAIR_WASM_PATH=JsClients/PAIR/wasm/pair-token.wasm -WASM_PATH=JsClients/ROUTER/wasm/uniswap-v2-router.wasm +ERC20_WASM_PATH=Scripts/ERC20/wasm/erc20-token.wasm +FACTORY_WASM_PATH=Scripts/FACTORY/wasm/factory.wasm +PAIR_WASM_PATH=Scripts/PAIR/wasm/pair-token.wasm +WASM_PATH=Scripts/ROUTER/wasm/uniswap-v2-router.wasm -ERC20_MASTER_KEY_PAIR_PATH=JsClients/ERC20/keys/ -FACTORY_MASTER_KEY_PAIR_PATH=JsClients/FACTORY/keys/ -PAIR_MASTER_KEY_PAIR_PATH=JsClients/PAIR/keys/ -MASTER_KEY_PAIR_PATH=JsClients/ROUTER/keys/ +ERC20_MASTER_KEY_PAIR_PATH=Scripts/ERC20/keys/ +FACTORY_MASTER_KEY_PAIR_PATH=Scripts/FACTORY/keys/ +PAIR_MASTER_KEY_PAIR_PATH=Scripts/PAIR/keys/ +MASTER_KEY_PAIR_PATH=Scripts/ROUTER/keys/ ERC20_CONTRACT_NAME=Wrapper Ether1 ERC20_TOKEN_NAME=Wrapper Ether @@ -124,8 +124,8 @@ TOKEN_SYMBOL=DRAG TOKEN_META=origin fire,lifetime infinite CONTRACT_NAME=UniSwapRouter1 -CONTRACT_HASH=2bd3b33f9d0a137a5790ebf0091d6bb5e0f47df6b7ca783989df8490c35875c7 -PACKAGE_HASH=ea048572fa8c13b56b58d512d9f3757823e42b74ad3273812ead895df6474d9d +ROUTER_CONTRACT_HASH=2bd3b33f9d0a137a5790ebf0091d6bb5e0f47df6b7ca783989df8490c35875c7 +ROUTER_PACKAGE_HASH=ea048572fa8c13b56b58d512d9f3757823e42b74ad3273812ead895df6474d9d INSTALL_PAYMENT_AMOUNT=300000000000 MINT_ONE_PAYMENT_AMOUNT=2000000000 MINT_COPIES_PAYMENT_AMOUNT=100000000000 diff --git a/.gitignore b/.gitignore index 0deb53ff..01658617 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,5 @@ /node_modules -# /JsClients/ERC20/keys -# /JsClients/FACTORY/keys -# /JsClients/PAIR/keys -# /JsClients/ROUTER/keys \ No newline at end of file +/Scripts/ERC20/keys +/Scripts/FACTORY/keys +/Scripts/PAIR/keys +/Scripts/ROUTER/keys \ No newline at end of file diff --git a/JsClients/ERC20/erc20FunctionsForBackend/functions.ts b/JsClients/ERC20/erc20FunctionsForBackend/functions.ts new file mode 100644 index 00000000..d88d5480 --- /dev/null +++ b/JsClients/ERC20/erc20FunctionsForBackend/functions.ts @@ -0,0 +1,98 @@ +import { config } from "dotenv"; +config(); +import { ERC20Client} from "../src"; + +const { + NODE_ADDRESS, + EVENT_STREAM_ADDRESS, + CHAIN_NAME +} = process.env; + +const erc20 = new ERC20Client( + NODE_ADDRESS!, + CHAIN_NAME!, + EVENT_STREAM_ADDRESS! +); + +export const getName = async (contractHash:string) => { + + // We don't need hash- prefix so i'm removing it + await erc20.setContractHash(contractHash); + + //name + const name = await erc20.name(); + console.log(contractHash +` =... Contract name: ${name}`); + + return name; + +}; + +export const getSymbol = async (contractHash:string) => { + + // We don't need hash- prefix so i'm removing it + await erc20.setContractHash(contractHash); + + //symbol + const symbol = await erc20.symbol(); + console.log(contractHash +` =... Contract symbol: ${symbol}`); + + return symbol; + +}; + +export const getDecimals = async (contractHash:string) => { + + // We don't need hash- prefix so i'm removing it + await erc20.setContractHash(contractHash); + + //decimal + const decimal = await erc20.decimal(); + console.log(contractHash +" =... Contract decimal: ", decimal); + + return decimal; + +}; + +export const getTotalSupply = async (contractHash:string) => { + + // We don't need hash- prefix so i'm removing it + await erc20.setContractHash(contractHash); + + //totalsupply + let totalSupply = await erc20.totalSupply(); + console.log(contractHash +` = ... Total supply: ${totalSupply}`); + + return totalSupply; + +}; + +export const balanceOf = async (contractHash:string, key:string) => { + + console.log(`... Contract Hash: ${contractHash}`); + + // We don't need hash- prefix so i'm removing it + await erc20.setContractHash(contractHash); + + //balanceof + let balance = await erc20.balanceOf(key); + + console.log(`... Balance: ${balance}`); + + return balance; + +}; + +export const allowance = async (contractHash:string, ownerkey:string, spenderkey:string) => { + + console.log(`... Contract Hash: ${contractHash}`); + + // We don't need hash- prefix so i'm removing it + await erc20.setContractHash(contractHash); + + let allowance = await erc20.allowance(ownerkey,spenderkey); + + console.log(`... Allowance: ${allowance}`); + + return allowance; + +}; diff --git a/JsClients/ERC20/keys/public_key.pem b/JsClients/ERC20/keys/public_key.pem deleted file mode 100644 index 27929cea..00000000 --- a/JsClients/ERC20/keys/public_key.pem +++ /dev/null @@ -1,3 +0,0 @@ ------BEGIN PUBLIC KEY----- -MCowBQYDK2VwAyEAXU0jCEGukxOfIxJFl0aPTp1/f2hHn1OUzNAHmBRmFQQ= ------END PUBLIC KEY----- diff --git a/JsClients/ERC20/keys/public_key_hex b/JsClients/ERC20/keys/public_key_hex deleted file mode 100644 index 9b27dcfb..00000000 --- a/JsClients/ERC20/keys/public_key_hex +++ /dev/null @@ -1 +0,0 @@ -015d4d230841ae93139f23124597468f4e9d7f7f68479f5394ccd0079814661504 \ No newline at end of file diff --git a/JsClients/ERC20/keys/secret_key.pem b/JsClients/ERC20/keys/secret_key.pem deleted file mode 100644 index 9447b6ce..00000000 --- a/JsClients/ERC20/keys/secret_key.pem +++ /dev/null @@ -1,3 +0,0 @@ ------BEGIN PRIVATE KEY----- -MC4CAQAwBQYDK2VwBCIEIGmu6s8jhbAznIU8GvBRnQcX9OfuEejuYpmqAuP+Xovs ------END PRIVATE KEY----- diff --git a/JsClients/ERC20/scripts/installed.ts b/JsClients/ERC20/scripts/installed.ts deleted file mode 100644 index e64e3c8e..00000000 --- a/JsClients/ERC20/scripts/installed.ts +++ /dev/null @@ -1,274 +0,0 @@ -import { config } from "dotenv"; -config(); -import { ERC20Client ,utils, constants} from "../src"; -import { sleep, getDeploy } from "./utils"; -import { request } from 'graphql-request'; - -import { - CLValueBuilder, - Keys, - CLPublicKey, - CLAccountHash, - CLPublicKeyType, - Contracts, - CLByteArray -} from "casper-js-sdk"; - -const { ERC20Events } = constants; - -const { - NODE_ADDRESS, - EVENT_STREAM_ADDRESS, - CHAIN_NAME, - ERC20_MASTER_KEY_PAIR_PATH, - ERC20_CONTRACT_NAME, - MINT_PAYMENT_AMOUNT, - MINT_AMOUNT, - BURN_PAYMENT_AMOUNT, - BURN_AMOUNT, - APPROVE_PAYMENT_AMOUNT, - APPROVE_AMOUNT, - TRANSFER_PAYMENT_AMOUNT, - TRANSFER_AMOUNT, - TRANSFER_FROM_PAYMENT_AMOUNT, - TRANSFER_FROM_AMOUNT, - TOKEN0_CONTRACT, - TOKEN1_CONTRACT, - TOKEN1_CONTRACT_PACKAGE, - PAIR_CONTRACT, - PACKAGE_HASH, - AMOUNT_A_DESIRED, - AMOUNT_B_DESIRED, - MASTER_KEY_PAIR_PATH, - PAIR_CONTRACT_PACKAGE, - GRAPHQL -} = process.env; - - -const KEYS = Keys.Ed25519.parseKeyFiles( - `${ERC20_MASTER_KEY_PAIR_PATH}/public_key.pem`, - `${ERC20_MASTER_KEY_PAIR_PATH}/secret_key.pem` -); - -const ROUTERKEYS = Keys.Ed25519.parseKeyFiles( - `${MASTER_KEY_PAIR_PATH}/public_key.pem`, - `${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 () => { - - await erc20.setContractHash(TOKEN1_CONTRACT!); - //console.log("contract:"+ TOKEN1_CONTRACT!); - //getTotalSupply(TOKEN1_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 - // console.log("user: 0d72ccd15e717fde4afc91fab70cb20e9986da52c670976386efc91b375f52a8"); - // let balance = await erc20.balanceOf("0d72ccd15e717fde4afc91fab70cb20e9986da52c670976386efc91b375f52a8"); - // 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( - 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, - // "70629f295bebdff4f09073a35946e56720f7aeb0214a9b7f59222b19a9297295", - // 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!); - // 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( - // ROUTERKEYS, - // PACKAGE_HASH!, - // AMOUNT_B_DESIRED!, - // APPROVE_PAYMENT_AMOUNT! - // ); - // console.log("... Approve deploy hash: ", approveDeployHash); - - // 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"); - -}; - - -//test(); - -export const getName = async (contractHash:string) => { - - // We don't need hash- prefix so i'm removing it - await erc20.setContractHash(contractHash); - - //name - const name = await erc20.name(); - console.log(contractHash +` =... Contract name: ${name}`); - - return name; - -}; - -export const getSymbol = async (contractHash:string) => { - - // We don't need hash- prefix so i'm removing it - await erc20.setContractHash(contractHash); - - //symbol - const symbol = await erc20.symbol(); - console.log(contractHash +` =... Contract symbol: ${symbol}`); - - return symbol; - -}; - -export const getDecimals = async (contractHash:string) => { - - // We don't need hash- prefix so i'm removing it - await erc20.setContractHash(contractHash); - - //decimal - const decimal = await erc20.decimal(); - console.log(contractHash +" =... Contract decimal: ", decimal); - - return decimal; - -}; - -export const getTotalSupply = async (contractHash:string) => { - - // We don't need hash- prefix so i'm removing it - await erc20.setContractHash(contractHash); - - //totalsupply - let totalSupply = await erc20.totalSupply(); - console.log(contractHash +` = ... Total supply: ${totalSupply}`); - - return totalSupply; - -}; - -export const balanceOf = async (contractHash:string, key:string) => { - - console.log(`... Contract Hash: ${contractHash}`); - - // We don't need hash- prefix so i'm removing it - await erc20.setContractHash(contractHash); - - //balanceof - let balance = await erc20.balanceOf(key); - - console.log(`... Balance: ${balance}`); - - return balance; - -}; - -export const allowance = async (contractHash:string, ownerkey:string, spenderkey:string) => { - - console.log(`... Contract Hash: ${contractHash}`); - - // We don't need hash- prefix so i'm removing it - await erc20.setContractHash(contractHash); - - let allowance = await erc20.allowance(ownerkey,spenderkey); - - console.log(`... Allowance: ${allowance}`); - - return allowance; - -}; - -//allowance("b761da7d5ef67f8825c30c40df8b72feca4724eb666dba556b0e3f67778143e0","8b217a09296d5ce360847a7d20f623476157c5f022333c4e988a464035cadd80","8a74e1ae230936013f3b544182b8011435f4a457d9444fa879ab483fdf829dc8"); \ No newline at end of file diff --git a/JsClients/ERC20/src/constants.ts b/JsClients/ERC20/src/constants.ts deleted file mode 100644 index 7817c7d2..00000000 --- a/JsClients/ERC20/src/constants.ts +++ /dev/null @@ -1,5 +0,0 @@ -export enum ERC20Events { - Approval="approve", - Transfer="erc20_transfer" -} - diff --git a/JsClients/ERC20/src/erc20.ts b/JsClients/ERC20/src/erc20.ts index 42d2f22d..8e036e82 100644 --- a/JsClients/ERC20/src/erc20.ts +++ b/JsClients/ERC20/src/erc20.ts @@ -11,17 +11,14 @@ import { CLValueParsers, CLMap, DeployUtil, - EventName, - EventStream, Keys, RuntimeArgs, } from "casper-js-sdk"; import { Some, None } from "ts-results"; import * as blake from "blakejs"; import { concat } from "@ethersproject/bytes"; -import { ERC20Events } from "./constants"; import * as utils from "./utils"; -import { RecipientType, IPendingDeploy } from "./types"; +import { RecipientType} from "./types"; import {createRecipientAddress } from "./utils"; class ERC20Client { @@ -39,9 +36,6 @@ class ERC20Client { }; - private isListening = false; - private pendingDeploys: IPendingDeploy[] = []; - constructor( private nodeAddress: string, @@ -154,6 +148,14 @@ class ERC20Client { ); return result.value(); } + public async totalSupply() { + const result = await contractSimpleGetter( + this.nodeAddress, + this.contractHash, + ["total_supply"] + ); + return result.value(); + } public async balanceOf(account: string) { try { @@ -170,22 +172,6 @@ class ERC20Client { } } - public async balanceOfcontract(accountHash: string) { - - try { - - const result = await utils.contractDictionaryGetter( - this.nodeAddress, - accountHash, - this.namedKeys.balances - ); - const maybeValue = result.value().unwrap(); - return maybeValue.value().toString(); - - } catch (error) { - return "0"; - } - } public async nonce(account: CLPublicKey) { const accountHash = Buffer.from(account.toAccountHash()).toString("hex"); @@ -224,15 +210,6 @@ class ERC20Client { } - public async totalSupply() { - const result = await contractSimpleGetter( - this.nodeAddress, - this.contractHash, - ["total_supply"] - ); - return result.value(); - } - public async approve( keys: Keys.AsymmetricKey, spender: string, @@ -357,35 +334,7 @@ class ERC20Client { 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, @@ -455,116 +404,6 @@ class ERC20Client { } } - public onEvent( - eventNames: ERC20Events[], - callback: ( - eventName: ERC20Events, - deployStatus: { - deployHash: string; - success: boolean; - error: string | null; - }, - result: any | null - ) => void - ): any { - if (!this.eventStreamAddress) { - throw Error("Please set eventStreamAddress before!"); - } - if (this.isListening) { - throw Error( - "Only one event listener can be create at a time. Remove the previous one and start new." - ); - } - const es = new EventStream(this.eventStreamAddress); - this.isListening = true; - - es.subscribe(EventName.DeployProcessed, (value: any) => { - const deployHash = value.body.DeployProcessed.deploy_hash; - - const pendingDeploy = this.pendingDeploys.find( - (pending) => pending.deployHash === deployHash - ); - - if (!pendingDeploy) { - return; - } - - if ( - !value.body.DeployProcessed.execution_result.Success && - value.body.DeployProcessed.execution_result.Failure - ) { - callback( - pendingDeploy.deployType, - { - deployHash, - error: - value.body.DeployProcessed.execution_result.Failure.error_message, - success: false, - }, - null - ); - } else { - const { transforms } = - value.body.DeployProcessed.execution_result.Success.effect; - - const ERC20Events = transforms.reduce((acc: any, val: any) => { - if ( - val.transform.hasOwnProperty("WriteCLValue") && - typeof val.transform.WriteCLValue.parsed === "object" && - val.transform.WriteCLValue.parsed !== null - ) { - const maybeCLValue = CLValueParsers.fromJSON( - val.transform.WriteCLValue - ); - const clValue = maybeCLValue.unwrap(); - if (clValue && clValue instanceof CLMap) { - const hash = clValue.get( - CLValueBuilder.string("contract_package_hash") - ); - const event = clValue.get(CLValueBuilder.string("event_type")); - if ( - hash && - // 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()) - ) { - acc = [...acc, { name: event.value(), clValue }]; - } - } - } - return acc; - }, []); - - ERC20Events.forEach((d: any) => - callback( - d.name, - { deployHash, error: null, success: true }, - d.clValue - ) - ); - } - - this.pendingDeploys = this.pendingDeploys.filter( - (pending) => pending.deployHash !== deployHash - ); - }); - es.start(); - - return { - stopListening: () => { - es.unsubscribe(EventName.DeployProcessed); - es.stop(); - this.isListening = false; - this.pendingDeploys = []; - }, - }; - } - - public addPendingDeploy(deployType: ERC20Events, deployHash: string) { - this.pendingDeploys = [...this.pendingDeploys, { deployHash, deployType }]; - } } interface IInstallParams { diff --git a/JsClients/ERC20/src/index.ts b/JsClients/ERC20/src/index.ts index 2c10e006..d4e5b4af 100644 --- a/JsClients/ERC20/src/index.ts +++ b/JsClients/ERC20/src/index.ts @@ -1,9 +1,7 @@ import ERC20Client from "./erc20"; import * as utils from "./utils"; -import * as constants from "./constants"; export { ERC20Client, - utils, - constants + utils }; diff --git a/JsClients/ERC20/src/types.d.ts b/JsClients/ERC20/src/types.d.ts index af90b09b..d29509ac 100644 --- a/JsClients/ERC20/src/types.d.ts +++ b/JsClients/ERC20/src/types.d.ts @@ -1,9 +1,7 @@ import { CLAccountHash, CLByteArray, CLPublicKey } from "casper-js-sdk"; -import {ERC20Events} from "./constants"; export type RecipientType = CLPublicKey | CLAccountHash | CLByteArray; export interface IPendingDeploy { deployHash: string; - deployType: ERC20Events; } diff --git a/JsClients/FACTORY/factoryFunctionsForBackend/functions.ts b/JsClients/FACTORY/factoryFunctionsForBackend/functions.ts new file mode 100644 index 00000000..9d5d89d5 --- /dev/null +++ b/JsClients/FACTORY/factoryFunctionsForBackend/functions.ts @@ -0,0 +1,30 @@ +import { config } from "dotenv"; +config(); +import { FACTORYClient} from "../src"; + +const { + NODE_ADDRESS, + EVENT_STREAM_ADDRESS, + CHAIN_NAME +} = process.env; + +const factory = new FACTORYClient( + NODE_ADDRESS!, + CHAIN_NAME!, + EVENT_STREAM_ADDRESS! +); + +export const getPair = async (contractHash:string,TOKEN0_CONTRACT:string,TOKEN1_CONTRACT:string) => { + + console.log(`... Contract Hash: ${contractHash}`); + + // We don't need hash- prefix so i'm removing it + await factory.setContractHash(contractHash); + + //pair + let pair = await factory.getPair(TOKEN0_CONTRACT, TOKEN1_CONTRACT); + console.log(`... Pair: ${pair}`); + + return pair; + +}; diff --git a/JsClients/FACTORY/keys/public_key.pem b/JsClients/FACTORY/keys/public_key.pem deleted file mode 100644 index 27929cea..00000000 --- a/JsClients/FACTORY/keys/public_key.pem +++ /dev/null @@ -1,3 +0,0 @@ ------BEGIN PUBLIC KEY----- -MCowBQYDK2VwAyEAXU0jCEGukxOfIxJFl0aPTp1/f2hHn1OUzNAHmBRmFQQ= ------END PUBLIC KEY----- diff --git a/JsClients/FACTORY/keys/public_key_hex b/JsClients/FACTORY/keys/public_key_hex deleted file mode 100644 index 9b27dcfb..00000000 --- a/JsClients/FACTORY/keys/public_key_hex +++ /dev/null @@ -1 +0,0 @@ -015d4d230841ae93139f23124597468f4e9d7f7f68479f5394ccd0079814661504 \ No newline at end of file diff --git a/JsClients/FACTORY/keys/secret_key.pem b/JsClients/FACTORY/keys/secret_key.pem deleted file mode 100644 index 9447b6ce..00000000 --- a/JsClients/FACTORY/keys/secret_key.pem +++ /dev/null @@ -1,3 +0,0 @@ ------BEGIN PRIVATE KEY----- -MC4CAQAwBQYDK2VwBCIEIGmu6s8jhbAznIU8GvBRnQcX9OfuEejuYpmqAuP+Xovs ------END PRIVATE KEY----- diff --git a/JsClients/FACTORY/src/constants.ts b/JsClients/FACTORY/src/constants.ts deleted file mode 100644 index b1fca830..00000000 --- a/JsClients/FACTORY/src/constants.ts +++ /dev/null @@ -1,3 +0,0 @@ -export enum FACTORYEvents { - PairCreated="pair_created" -} diff --git a/JsClients/FACTORY/src/factory.ts b/JsClients/FACTORY/src/factory.ts index 7761967d..ac430146 100644 --- a/JsClients/FACTORY/src/factory.ts +++ b/JsClients/FACTORY/src/factory.ts @@ -11,22 +11,16 @@ import { CLValueParsers, CLMap, DeployUtil, - EventName, - EventStream, Keys, RuntimeArgs, } from "casper-js-sdk"; -import { FACTORYEvents } from "./constants"; import * as utils from "./utils"; -import { RecipientType, IPendingDeploy } from "./types"; +import { RecipientType } from "./types"; class FACTORYClient { private contractHash: string="factory"; private contractPackageHash: string="factory"; - private isListening = false; - private pendingDeploys: IPendingDeploy[] = []; - constructor( private nodeAddress: string, private chainName: string, @@ -36,14 +30,12 @@ class FACTORYClient { public async install( keys: Keys.AsymmetricKey, contractName: string, - // feeTo: RecipientType, feeToSetter: RecipientType, paymentAmount: string, wasmPath: string ) { const runtimeArgs = RuntimeArgs.fromMap({ contract_name: CLValueBuilder.string(contractName), - // fee_to: utils.createRecipientAddress(feeTo), fee_to_setter: utils.createRecipientAddress(feeToSetter), }); @@ -250,117 +242,6 @@ class FACTORYClient { throw Error("Invalid Deploy"); } } - - public onEvent( - eventNames: FACTORYEvents[], - callback: ( - eventName: FACTORYEvents, - deployStatus: { - deployHash: string; - success: boolean; - error: string | null; - }, - result: any | null - ) => void - ): any { - if (!this.eventStreamAddress) { - throw Error("Please set eventStreamAddress before!"); - } - if (this.isListening) { - throw Error( - "Only one event listener can be create at a time. Remove the previous one and start new." - ); - } - const es = new EventStream(this.eventStreamAddress); - this.isListening = true; - - es.subscribe(EventName.DeployProcessed, (value: any) => { - const deployHash = value.body.DeployProcessed.deploy_hash; - - const pendingDeploy = this.pendingDeploys.find( - (pending) => pending.deployHash === deployHash - ); - - if (!pendingDeploy) { - return; - } - - if ( - !value.body.DeployProcessed.execution_result.Success && - value.body.DeployProcessed.execution_result.Failure - ) { - callback( - pendingDeploy.deployType, - { - deployHash, - error: - value.body.DeployProcessed.execution_result.Failure.error_message, - success: false, - }, - null - ); - } else { - const { transforms } = - value.body.DeployProcessed.execution_result.Success.effect; - - const factoryEvents = transforms.reduce((acc: any, val: any) => { - if ( - val.transform.hasOwnProperty("WriteCLValue") && - typeof val.transform.WriteCLValue.parsed === "object" && - val.transform.WriteCLValue.parsed !== null - ) { - const maybeCLValue = CLValueParsers.fromJSON( - val.transform.WriteCLValue - ); - const clValue = maybeCLValue.unwrap(); - if (clValue && clValue instanceof CLMap) { - const hash = clValue.get( - CLValueBuilder.string("contract_package_hash") - ); - const event = clValue.get(CLValueBuilder.string("event_type")); - if ( - hash && - // 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()) - ) { - acc = [...acc, { name: event.value(), clValue }]; - } - } - } - return acc; - }, []); - - factoryEvents.forEach((d: any) => - callback( - d.name, - { deployHash, error: null, success: true }, - d.clValue - ) - ); - } - - this.pendingDeploys = this.pendingDeploys.filter( - (pending) => pending.deployHash !== deployHash - ); - }); - es.start(); - - return { - stopListening: () => { - es.unsubscribe(EventName.DeployProcessed); - es.stop(); - this.isListening = false; - this.pendingDeploys = []; - }, - }; - } - - private addPendingDeploy(deployType: FACTORYEvents, deployHash: string) { - this.pendingDeploys = [...this.pendingDeploys, { deployHash, deployType }]; - } } interface IInstallParams { diff --git a/JsClients/FACTORY/src/index.ts b/JsClients/FACTORY/src/index.ts index 68c565dd..f20dc17f 100644 --- a/JsClients/FACTORY/src/index.ts +++ b/JsClients/FACTORY/src/index.ts @@ -1,9 +1,7 @@ import FACTORYClient from "./factory"; import * as utils from "./utils"; -import * as constants from "./constants"; export { FACTORYClient, - utils, - constants + utils }; diff --git a/JsClients/FACTORY/src/types.d.ts b/JsClients/FACTORY/src/types.d.ts index 2e4ae4e1..d29509ac 100644 --- a/JsClients/FACTORY/src/types.d.ts +++ b/JsClients/FACTORY/src/types.d.ts @@ -4,5 +4,4 @@ export type RecipientType = CLPublicKey | CLAccountHash | CLByteArray; export interface IPendingDeploy { deployHash: string; - deployType: FACTORYEvents; } diff --git a/JsClients/PAIR/keys/public_key.pem b/JsClients/PAIR/keys/public_key.pem deleted file mode 100644 index 27929cea..00000000 --- a/JsClients/PAIR/keys/public_key.pem +++ /dev/null @@ -1,3 +0,0 @@ ------BEGIN PUBLIC KEY----- -MCowBQYDK2VwAyEAXU0jCEGukxOfIxJFl0aPTp1/f2hHn1OUzNAHmBRmFQQ= ------END PUBLIC KEY----- diff --git a/JsClients/PAIR/keys/public_key_hex b/JsClients/PAIR/keys/public_key_hex deleted file mode 100644 index 9b27dcfb..00000000 --- a/JsClients/PAIR/keys/public_key_hex +++ /dev/null @@ -1 +0,0 @@ -015d4d230841ae93139f23124597468f4e9d7f7f68479f5394ccd0079814661504 \ No newline at end of file diff --git a/JsClients/PAIR/keys/secret_key.pem b/JsClients/PAIR/keys/secret_key.pem deleted file mode 100644 index 9447b6ce..00000000 --- a/JsClients/PAIR/keys/secret_key.pem +++ /dev/null @@ -1,3 +0,0 @@ ------BEGIN PRIVATE KEY----- -MC4CAQAwBQYDK2VwBCIEIGmu6s8jhbAznIU8GvBRnQcX9OfuEejuYpmqAuP+Xovs ------END PRIVATE KEY----- diff --git a/JsClients/PAIR/pairFunctionsForBackend/functions.ts b/JsClients/PAIR/pairFunctionsForBackend/functions.ts new file mode 100644 index 00000000..232fb62e --- /dev/null +++ b/JsClients/PAIR/pairFunctionsForBackend/functions.ts @@ -0,0 +1,77 @@ +import { config } from "dotenv"; +config(); +import { PAIRClient} from "../src"; + +const { + NODE_ADDRESS, + EVENT_STREAM_ADDRESS, + CHAIN_NAME, + PAIR_CONTRACT_NAME, + PAIR_TOKEN_NAME, + PAIR_TOKEN_SYMBOL, + PAIR_DECIMALS, + PAIR_TOTAL_SUPPLY, + PAIR_INSTALL_PAYMENT_AMOUNT, + PAIR_WASM_PATH, +} = process.env; + + +const pair = new PAIRClient( + NODE_ADDRESS!, + CHAIN_NAME!, + EVENT_STREAM_ADDRESS! +); + +export const balanceOf = async (contractHash:string, key:string) => { + + console.log(`... Contract Hash: ${contractHash}`); + + // We don't need hash- prefix so i'm removing it + await pair.setContractHash(contractHash); + + //balanceof + let balance = await pair.balanceOf(key); + + console.log(`... Balance: ${balance}`); + + return balance; + +}; +export const allowance = async (contractHash:string, ownerkey:string, spenderkey:string) => { + + console.log(`... Contract Hash: ${contractHash}`); + + // We don't need hash- prefix so i'm removing it + await pair.setContractHash(contractHash); + + let allowance = await pair.allowance(ownerkey,spenderkey); + + console.log(`... Allowance: ${allowance}`); + + return allowance; + +}; + +export const makedeploypaircontract = async ( + FACTORY_CONTRACT_PACKAGE: string, + CALLEE_PACKAGE: string, + signerkey:string, +) => { + + const deployJSON = await pair.makedeployJSON( + signerkey, + PAIR_CONTRACT_NAME!, + PAIR_TOKEN_NAME!, + PAIR_TOKEN_SYMBOL!, + PAIR_DECIMALS!, + PAIR_TOTAL_SUPPLY!, + FACTORY_CONTRACT_PACKAGE!, + CALLEE_PACKAGE!, + PAIR_INSTALL_PAYMENT_AMOUNT!, + PAIR_WASM_PATH! + ); + + console.log(`... Contract make deploy SuccessFull: ${deployJSON}`); + return deployJSON; + +}; diff --git a/JsClients/PAIR/src/constants.ts b/JsClients/PAIR/src/constants.ts deleted file mode 100644 index fda55428..00000000 --- a/JsClients/PAIR/src/constants.ts +++ /dev/null @@ -1,10 +0,0 @@ -export enum PAIREvents { - Approval = 'approve', - Transfer = 'transfer', - Erc20Transfer = 'erc20_transfer', - Mint = 'mint', - Burn = 'burn', - Sync = 'sync', - Swap = 'swap', - -} diff --git a/JsClients/PAIR/src/index.ts b/JsClients/PAIR/src/index.ts index fd84d677..e1e3c753 100644 --- a/JsClients/PAIR/src/index.ts +++ b/JsClients/PAIR/src/index.ts @@ -1,9 +1,7 @@ import PAIRClient from "./pair"; import * as utils from "./utils"; -import * as constants from "./constants"; export { PAIRClient, - utils, - constants + utils }; diff --git a/JsClients/PAIR/src/pair.ts b/JsClients/PAIR/src/pair.ts index 943a6a49..0805e44e 100644 --- a/JsClients/PAIR/src/pair.ts +++ b/JsClients/PAIR/src/pair.ts @@ -11,16 +11,13 @@ import { CLValueParsers, CLMap, DeployUtil, - EventName, - EventStream, Keys, RuntimeArgs, } from "casper-js-sdk"; import * as blake from "blakejs"; import { concat } from "@ethersproject/bytes"; -import { PAIREvents } from "./constants"; import * as utils from "./utils"; -import { RecipientType, IPendingDeploy } from "./types"; +import { RecipientType} from "./types"; import {createRecipientAddress } from "./utils"; class PAIRClient { @@ -36,8 +33,6 @@ class PAIRClient { owners: string; paused: string; }; - private isListening = false; - private pendingDeploys: IPendingDeploy[] = []; constructor( private nodeAddress: string, @@ -72,12 +67,6 @@ class PAIRClient { const _factoryContractHash = new CLByteArray(Uint8Array.from(Buffer.from(factoryContractHash, 'hex'))); const _calleeContractHash = new CLByteArray(Uint8Array.from(Buffer.from(calleeContractHash, 'hex'))); - // const runtimeArgs = RuntimeArgs.fromMap({ - // contract_name: CLValueBuilder.string(contractName), - // factory_hash: CLValueBuilder.key(_factoryContractHash), - // callee_contract_hash: CLValueBuilder.key(_calleeContractHash), - // }); - const runtimeArgs = RuntimeArgs.fromMap({ contract_name: CLValueBuilder.string(contractName), name: CLValueBuilder.string(tokenName), @@ -744,118 +733,6 @@ class PAIRClient { } } - - - public onEvent( - eventNames: PAIREvents[], - callback: ( - eventName: PAIREvents, - deployStatus: { - deployHash: string; - success: boolean; - error: string | null; - }, - result: any | null - ) => void - ): any { - if (!this.eventStreamAddress) { - throw Error("Please set eventStreamAddress before!"); - } - if (this.isListening) { - throw Error( - "Only one event listener can be create at a time. Remove the previous one and start new." - ); - } - const es = new EventStream(this.eventStreamAddress); - this.isListening = true; - - es.subscribe(EventName.DeployProcessed, (value: any) => { - const deployHash = value.body.DeployProcessed.deploy_hash; - - const pendingDeploy = this.pendingDeploys.find( - (pending) => pending.deployHash === deployHash - ); - - if (!pendingDeploy) { - return; - } - - if ( - !value.body.DeployProcessed.execution_result.Success && - value.body.DeployProcessed.execution_result.Failure - ) { - callback( - pendingDeploy.deployType, - { - deployHash, - error: - value.body.DeployProcessed.execution_result.Failure.error_message, - success: false, - }, - null - ); - } else { - const { transforms } = - value.body.DeployProcessed.execution_result.Success.effect; - - const PAIREvents = transforms.reduce((acc: any, val: any) => { - if ( - val.transform.hasOwnProperty("WriteCLValue") && - typeof val.transform.WriteCLValue.parsed === "object" && - val.transform.WriteCLValue.parsed !== null - ) { - const maybeCLValue = CLValueParsers.fromJSON( - val.transform.WriteCLValue - ); - const clValue = maybeCLValue.unwrap(); - if (clValue && clValue instanceof CLMap) { - const hash = clValue.get( - CLValueBuilder.string("contract_package_hash") - ); - const event = clValue.get(CLValueBuilder.string("event_type")); - if ( - hash && - // 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()) - ){ - acc = [...acc, { name: event.value(), clValue }]; - } - } - } - return acc; - }, []); - - PAIREvents.forEach((d: any) => - callback( - d.name, - { deployHash, error: null, success: true }, - d.clValue - ) - ); - } - - this.pendingDeploys = this.pendingDeploys.filter( - (pending) => pending.deployHash !== deployHash - ); - }); - es.start(); - - return { - stopListening: () => { - es.unsubscribe(EventName.DeployProcessed); - es.stop(); - this.isListening = false; - this.pendingDeploys = []; - }, - }; - } - - private addPendingDeploy(deployType: PAIREvents, deployHash: string) { - this.pendingDeploys = [...this.pendingDeploys, { deployHash, deployType }]; - } } interface IInstallParams { diff --git a/JsClients/PAIR/src/types.d.ts b/JsClients/PAIR/src/types.d.ts index 80536910..d29509ac 100644 --- a/JsClients/PAIR/src/types.d.ts +++ b/JsClients/PAIR/src/types.d.ts @@ -4,5 +4,4 @@ export type RecipientType = CLPublicKey | CLAccountHash | CLByteArray; export interface IPendingDeploy { deployHash: string; - deployType: PAIREvents; } diff --git a/JsClients/ROUTER/keys/public_key.pem b/JsClients/ROUTER/keys/public_key.pem deleted file mode 100644 index 27929cea..00000000 --- a/JsClients/ROUTER/keys/public_key.pem +++ /dev/null @@ -1,3 +0,0 @@ ------BEGIN PUBLIC KEY----- -MCowBQYDK2VwAyEAXU0jCEGukxOfIxJFl0aPTp1/f2hHn1OUzNAHmBRmFQQ= ------END PUBLIC KEY----- diff --git a/JsClients/ROUTER/keys/public_key_hex b/JsClients/ROUTER/keys/public_key_hex deleted file mode 100644 index 9b27dcfb..00000000 --- a/JsClients/ROUTER/keys/public_key_hex +++ /dev/null @@ -1 +0,0 @@ -015d4d230841ae93139f23124597468f4e9d7f7f68479f5394ccd0079814661504 \ No newline at end of file diff --git a/JsClients/ROUTER/keys/secret_key.pem b/JsClients/ROUTER/keys/secret_key.pem deleted file mode 100644 index 9447b6ce..00000000 --- a/JsClients/ROUTER/keys/secret_key.pem +++ /dev/null @@ -1,3 +0,0 @@ ------BEGIN PRIVATE KEY----- -MC4CAQAwBQYDK2VwBCIEIGmu6s8jhbAznIU8GvBRnQcX9OfuEejuYpmqAuP+Xovs ------END PRIVATE KEY----- diff --git a/JsClients/ROUTER/routerFunctionsForBackend/functions.ts b/JsClients/ROUTER/routerFunctionsForBackend/functions.ts new file mode 100644 index 00000000..b46974b3 --- /dev/null +++ b/JsClients/ROUTER/routerFunctionsForBackend/functions.ts @@ -0,0 +1,44 @@ +import { config } from "dotenv"; +config(); +import { UniswapRouterClient } from "../src"; + +const { + NODE_ADDRESS, + EVENT_STREAM_ADDRESS, + CHAIN_NAME, + ROUTER_CONTRACT_HASH +} = process.env; + + +const uniswapRouter = new UniswapRouterClient( + NODE_ADDRESS!, + CHAIN_NAME!, + EVENT_STREAM_ADDRESS! +); + +export const swapforinterface = async ( + signerkey:string, + amountin: string, + amountout: string, + paths:string[], + to:string, + deadline:string, + installpaymentamount:string +) => { + + await uniswapRouter.setContractHash(ROUTER_CONTRACT_HASH!); + console.log("key:",signerkey); + const deploy = await uniswapRouter.swap_exact_tokens_for_tokensinterface( + signerkey, + amountin, + amountout, + paths, + to, + deadline, + installpaymentamount + ); + + console.log(`... Swap make deploy SuccessFull: ${deploy}`); + return deploy; + +}; \ No newline at end of file diff --git a/JsClients/ROUTER/src/constants.ts b/JsClients/ROUTER/src/constants.ts deleted file mode 100644 index b8c698e3..00000000 --- a/JsClients/ROUTER/src/constants.ts +++ /dev/null @@ -1,10 +0,0 @@ -export enum RouterEvents { - PairCreated="pair_created", - Approval = 'approve', - Erc20Transfer='erc20_transfer', - Transfer = 'transfer', - Mint = 'mint', - Burn = 'burn', - Sync = 'sync', - Swap = 'swap' -} diff --git a/JsClients/ROUTER/src/index.ts b/JsClients/ROUTER/src/index.ts index c4321bc7..9012b4a1 100644 --- a/JsClients/ROUTER/src/index.ts +++ b/JsClients/ROUTER/src/index.ts @@ -1,9 +1,7 @@ import UniswapRouterClient from "./uniswap-router-client"; import * as utils from "./utils"; -import * as constants from "./constants"; export { UniswapRouterClient, - utils, - constants + utils }; diff --git a/JsClients/ROUTER/src/types.d.ts b/JsClients/ROUTER/src/types.d.ts index 15cbf6ba..d29509ac 100644 --- a/JsClients/ROUTER/src/types.d.ts +++ b/JsClients/ROUTER/src/types.d.ts @@ -1,9 +1,7 @@ import { CLAccountHash, CLByteArray, CLPublicKey } from "casper-js-sdk"; -import {RouterEvents} from "./constants"; export type RecipientType = CLPublicKey | CLAccountHash | CLByteArray; export interface IPendingDeploy { deployHash: string; - deployType: RouterEvents; } diff --git a/JsClients/ROUTER/src/uniswap-router-client.ts b/JsClients/ROUTER/src/uniswap-router-client.ts index ce0e746d..b5bebe9e 100644 --- a/JsClients/ROUTER/src/uniswap-router-client.ts +++ b/JsClients/ROUTER/src/uniswap-router-client.ts @@ -11,8 +11,6 @@ import { CLValueParsers, CLMap, DeployUtil, - EventName, - EventStream, Keys, RuntimeArgs, CLKeyParameters, @@ -23,11 +21,7 @@ import { CLOptionType } from "casper-js-sdk"; import { Some, None } from "ts-results"; -import { RouterEvents } from "./constants"; import * as utils from "./utils"; -import { RecipientType, IPendingDeploy } from "./types"; -import { ContractType } from "casper-js-sdk/dist/lib/DeployUtil"; -import { Key } from "readline"; const axios = require("axios").default; class UniswapRouterClient { @@ -41,8 +35,6 @@ class UniswapRouterClient { owners: string; paused: string; }; - private isListening = false; - private pendingDeploys: IPendingDeploy[] = []; constructor( private nodeAddress: string, @@ -724,117 +716,6 @@ class UniswapRouterClient { } } - public onEvent( - eventNames: RouterEvents[], - callback: ( - eventName: RouterEvents, - deployStatus: { - deployHash: string; - success: boolean; - error: string | null; - }, - result: any | null - ) => void - ): any { - if (!this.eventStreamAddress) { - throw Error("Please set eventStreamAddress before!"); - } - if (this.isListening) { - throw Error( - "Only one event listener can be create at a time. Remove the previous one and start new." - ); - } - const es = new EventStream(this.eventStreamAddress); - this.isListening = true; - - es.subscribe(EventName.DeployProcessed, (value: any) => { - const deployHash = value.body.DeployProcessed.deploy_hash; - - const pendingDeploy = this.pendingDeploys.find( - (pending) => pending.deployHash === deployHash - ); - - if (!pendingDeploy) { - return; - } - - if ( - !value.body.DeployProcessed.execution_result.Success && - value.body.DeployProcessed.execution_result.Failure - ) { - callback( - pendingDeploy.deployType, - { - deployHash, - error: - value.body.DeployProcessed.execution_result.Failure.error_message, - success: false, - }, - null - ); - } else { - const { transforms } = - value.body.DeployProcessed.execution_result.Success.effect; - - const RouterEvents = transforms.reduce((acc: any, val: any) => { - if ( - val.transform.hasOwnProperty("WriteCLValue") && - typeof val.transform.WriteCLValue.parsed === "object" && - val.transform.WriteCLValue.parsed !== null - ) { - const maybeCLValue = CLValueParsers.fromJSON( - val.transform.WriteCLValue - ); - const clValue = maybeCLValue.unwrap(); - if (clValue && clValue instanceof CLMap) { - const hash = clValue.get( - CLValueBuilder.string("contract_package_hash") - ); - const event = clValue.get(CLValueBuilder.string("event_type")); - if ( - hash && - // 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()) - ) { - acc = [...acc, { name: event.value(), clValue }]; - } - } - } - return acc; - }, []); - - RouterEvents.forEach((d: any) => - callback( - d.name, - { deployHash, error: null, success: true }, - d.clValue - ) - ); - } - - this.pendingDeploys = this.pendingDeploys.filter( - (pending) => pending.deployHash !== deployHash - ); - }); - es.start(); - - return { - stopListening: () => { - es.unsubscribe(EventName.DeployProcessed); - es.stop(); - this.isListening = false; - this.pendingDeploys = []; - }, - }; - } - - private addPendingDeploy(deployType: RouterEvents, deployHash: string) { - this.pendingDeploys = [...this.pendingDeploys, { deployHash, deployType }]; - } - public async registerWebHook(backendLink: String, endpointLink: String) { let axiosStatus; await axios({ diff --git a/JsClients/ERC20/scripts/install.ts b/Scripts/ERC20/deploy/erc20Contract.ts similarity index 90% rename from JsClients/ERC20/scripts/install.ts rename to Scripts/ERC20/deploy/erc20Contract.ts index b1dd1453..ef67c79a 100644 --- a/JsClients/ERC20/scripts/install.ts +++ b/Scripts/ERC20/deploy/erc20Contract.ts @@ -1,10 +1,10 @@ import { config } from "dotenv"; config(); -import { ERC20Client, utils, constants } from "../src"; -import { parseTokenMeta, sleep, getDeploy } from "./utils"; +import { ERC20Client, utils } from "../../../JsClients/ERC20/src"; +import { getDeploy } from "./utils"; import { - Keys, + Keys } from "casper-js-sdk"; const { @@ -26,7 +26,7 @@ const KEYS = Keys.Ed25519.parseKeyFiles( `${ERC20_MASTER_KEY_PAIR_PATH}/secret_key.pem` ); -const test = async () => { +const deploy = async () => { const erc20 = new ERC20Client( NODE_ADDRESS!, CHAIN_NAME!, @@ -70,4 +70,4 @@ const test = async () => { console.log(`... Package Hash: ${packageHash}`); }; -//test(); +//deploy(); diff --git a/Scripts/ERC20/deploy/erc20ContractFunctions.ts b/Scripts/ERC20/deploy/erc20ContractFunctions.ts new file mode 100644 index 00000000..226d7fae --- /dev/null +++ b/Scripts/ERC20/deploy/erc20ContractFunctions.ts @@ -0,0 +1,160 @@ +import { config } from "dotenv"; +config(); +import { ERC20Client } from "../../../JsClients/ERC20/src"; +import { getDeploy } from "./utils"; + +import { + CLValueBuilder, + Keys, + CLPublicKey, + CLAccountHash, + CLPublicKeyType, + Contracts, + CLByteArray +} from "casper-js-sdk"; + +const { + NODE_ADDRESS, + EVENT_STREAM_ADDRESS, + CHAIN_NAME, + ERC20_MASTER_KEY_PAIR_PATH, + ERC20_CONTRACT_NAME, + MINT_PAYMENT_AMOUNT, + MINT_AMOUNT, + BURN_PAYMENT_AMOUNT, + BURN_AMOUNT, + APPROVE_PAYMENT_AMOUNT, + APPROVE_AMOUNT, + TRANSFER_PAYMENT_AMOUNT, + TRANSFER_AMOUNT, + TRANSFER_FROM_PAYMENT_AMOUNT, + TRANSFER_FROM_AMOUNT, + TOKEN0_CONTRACT, + TOKEN1_CONTRACT, + TOKEN1_CONTRACT_PACKAGE, + PAIR_CONTRACT, + ROUTER_PACKAGE_HASH, + AMOUNT_A_DESIRED, + AMOUNT_B_DESIRED, + MASTER_KEY_PAIR_PATH, + PAIR_CONTRACT_PACKAGE, + GRAPHQL +} = process.env; + + +const KEYS = Keys.Ed25519.parseKeyFiles( + `${ERC20_MASTER_KEY_PAIR_PATH}/public_key.pem`, + `${ERC20_MASTER_KEY_PAIR_PATH}/secret_key.pem` +); + +const erc20 = new ERC20Client( + NODE_ADDRESS!, + CHAIN_NAME!, + EVENT_STREAM_ADDRESS! +); + +const deploy = async () => { + + await erc20.setContractHash(TOKEN1_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("282fabb87a057d991937770223de98ae86f6e652a050825aa196dfd4f480029e"); + // console.log(`... Balance: ${balance}`); + + // // //nonce + // let nonce = await erc20.nonce(KEYS.publicKey); + // console.log(`... Nonce: ${nonce}`); + + // //allowance + // let allowance = await erc20.allowance("282fabb87a057d991937770223de98ae86f6e652a050825aa196dfd4f480029e","282fabb87a057d991937770223de98ae86f6e652a050825aa196dfd4f480029e"); + // console.log(`... Allowance: ${allowance}`); + + //mint + const mintDeployHash = await erc20.mint( + KEYS, + KEYS.publicKey, + MINT_AMOUNT!, + MINT_PAYMENT_AMOUNT! + ); + console.log("... Mint deploy hash: ", mintDeployHash); + + await getDeploy(NODE_ADDRESS!, mintDeployHash); + console.log("... Token minted successfully."); + + // // //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, + // ROUTER_PACKAGE_HASH!, + // AMOUNT_B_DESIRED!, + // APPROVE_PAYMENT_AMOUNT! + // ); + // console.log("... Approve deploy hash: ", approveDeployHash); + + // 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"); + +}; + +//deploy(); + + + + diff --git a/JsClients/ERC20/scripts/utils.ts b/Scripts/ERC20/deploy/utils.ts similarity index 100% rename from JsClients/ERC20/scripts/utils.ts rename to Scripts/ERC20/deploy/utils.ts diff --git a/JsClients/ERC20/wasm/erc20-token.wasm b/Scripts/ERC20/wasm/erc20-token.wasm old mode 100755 new mode 100644 similarity index 100% rename from JsClients/ERC20/wasm/erc20-token.wasm rename to Scripts/ERC20/wasm/erc20-token.wasm diff --git a/JsClients/ERC20/wasm/purse-proxy.wasm b/Scripts/ERC20/wasm/purse-proxy.wasm similarity index 100% rename from JsClients/ERC20/wasm/purse-proxy.wasm rename to Scripts/ERC20/wasm/purse-proxy.wasm diff --git a/JsClients/FACTORY/scripts/install.ts b/Scripts/FACTORY/deploy/factoryContract.ts similarity index 90% rename from JsClients/FACTORY/scripts/install.ts rename to Scripts/FACTORY/deploy/factoryContract.ts index 12397100..3e6c5e47 100644 --- a/JsClients/FACTORY/scripts/install.ts +++ b/Scripts/FACTORY/deploy/factoryContract.ts @@ -1,7 +1,7 @@ import { config } from "dotenv"; config(); -import { FACTORYClient, utils, constants } from "../src"; -import { parseTokenMeta, sleep, getDeploy } from "./utils"; +import { FACTORYClient, utils } from "../../../JsClients/FACTORY/src"; +import { getDeploy } from "./utils"; import { Keys, @@ -22,7 +22,7 @@ const KEYS = Keys.Ed25519.parseKeyFiles( `${FACTORY_MASTER_KEY_PAIR_PATH}/secret_key.pem` ); -const test = async () => { +const deploy = async () => { const factory = new FACTORYClient( NODE_ADDRESS!, CHAIN_NAME!, @@ -66,4 +66,4 @@ const test = async () => { }; -//test(); +//deploy(); diff --git a/JsClients/FACTORY/scripts/installed.ts b/Scripts/FACTORY/deploy/factoryContractFunctions.ts similarity index 60% rename from JsClients/FACTORY/scripts/installed.ts rename to Scripts/FACTORY/deploy/factoryContractFunctions.ts index b83fcd23..56e2d2f0 100644 --- a/JsClients/FACTORY/scripts/installed.ts +++ b/Scripts/FACTORY/deploy/factoryContractFunctions.ts @@ -1,8 +1,7 @@ import { config } from "dotenv"; config(); -import { FACTORYClient, utils, constants } from "../src"; -import { parseTokenMeta, sleep, getDeploy } from "./utils"; -import { request } from 'graphql-request'; +import { FACTORYClient, utils} from "../../../JsClients/FACTORY/src"; +import { getDeploy } from "./utils"; import { CLValueBuilder, @@ -12,8 +11,6 @@ import { CLPublicKeyType, } from "casper-js-sdk"; -const { FACTORYEvents } = constants; - const { NODE_ADDRESS, EVENT_STREAM_ADDRESS, @@ -27,7 +24,7 @@ const { TOKEN1_CONTRACT, PAIR_CONTRACT, FACTORY_CONTRACT, - PACKAGE_HASH, + ROUTER_PACKAGE_HASH, GRAPHQL } = process.env; @@ -42,32 +39,20 @@ const factory = new FACTORYClient( EVENT_STREAM_ADDRESS! ); -function splitdata(data:string) -{ - var temp=data.split('('); - var result=temp[1].split(')'); - return result[0]; -} - -const test = async () => { +const deploy = async () => { - await sleep(5 * 1000); - - let accountInfo = await utils.getAccountInfo(NODE_ADDRESS!, KEYS.publicKey); - - console.log(`... Account Info: `); - console.log(JSON.stringify(accountInfo, null, 2)); + await factory.setContractHash(FACTORY_CONTRACT!); - const contractHash = await utils.getAccountNamedKeyValue( - accountInfo, - `${CONTRACT_NAME!}_contract_hash` + //whiteList Router + const set_white_list_deployHash = await factory.set_white_list( + KEYS, + ROUTER_PACKAGE_HASH!, + CREATE_PAIR_PAYMENT_AMOUNT! ); + console.log("... Set WhiteList deploy hash: ", set_white_list_deployHash); - console.log(`... Contract Hash: ${contractHash}`); - - // We don't need hash- prefix so i'm removing it - // await factory.setContractHash(contractHash.slice(5)); - await factory.setContractHash( FACTORY_CONTRACT!); + await getDeploy(NODE_ADDRESS!, set_white_list_deployHash); + console.log("... Router is whitelisted successfully."); // //feetosetter // const feetosetter = await factory.feeToSetter(); @@ -77,7 +62,7 @@ const test = async () => { // const allpairs = await factory.allPairs(); // console.log(`... Contract allpairs: ${allpairs}`); - //createpair + // //createpair // const createpairDeployHash = await factory.createPair( // KEYS, // TOKEN0_CONTRACT!, @@ -89,15 +74,6 @@ const test = async () => { // await getDeploy(NODE_ADDRESS!, createpairDeployHash); // console.log("... Pair created successfully"); - const set_white_list_deployHash = await factory.set_white_list( - KEYS, - PACKAGE_HASH!, - CREATE_PAIR_PAYMENT_AMOUNT! - ); - console.log("... Set WhiteList deploy hash: ", set_white_list_deployHash); - - await getDeploy(NODE_ADDRESS!, set_white_list_deployHash); - console.log("... Router is whitelisted successfully."); // //allpairs // const allPairs = await factory.allPairs(); @@ -143,35 +119,4 @@ const test = async () => { }; -//test(); - -// export const createPair = async (paircontractHash:string,TOKEN0_CONTRACT:string,TOKEN1_CONTRACT:string) => { - -// console.log(`... Contract Hash: ${paircontractHash}`); - -// // We don't need hash- prefix so i'm removing it -// await factory.setContractHash(paircontractHash); - -// //pair -// let pair = await factory.createPair(TOKEN0_CONTRACT, TOKEN1_CONTRACT,paircontractHash); -// console.log(`... Pair: ${pair}`); - -// return pair; - -// }; - -export const getPair = async (contractHash:string,TOKEN0_CONTRACT:string,TOKEN1_CONTRACT:string) => { - - console.log(`... Contract Hash: ${contractHash}`); - - // We don't need hash- prefix so i'm removing it - await factory.setContractHash(contractHash); - - //pair - let pair = await factory.getPair(TOKEN0_CONTRACT, TOKEN1_CONTRACT); - console.log(`... Pair: ${pair}`); - - return pair; - -}; -//getPair("202dffe0821C291870c864378c38fCE0BC4Fe7EA571341c62243e92608005BEe","4ae77D7D5ae22b60fC9CA97d952617C1f312b9740771E0e380Da909Bf8A8e2f2","c71567459Ba27504318e44948891cF42eb506b4BE1d31B81eA0280a65a22A3D9"); +//deploy(); diff --git a/JsClients/FACTORY/scripts/utils.ts b/Scripts/FACTORY/deploy/utils.ts similarity index 100% rename from JsClients/FACTORY/scripts/utils.ts rename to Scripts/FACTORY/deploy/utils.ts diff --git a/JsClients/FACTORY/wasm/factory.wasm b/Scripts/FACTORY/wasm/factory.wasm old mode 100755 new mode 100644 similarity index 100% rename from JsClients/FACTORY/wasm/factory.wasm rename to Scripts/FACTORY/wasm/factory.wasm diff --git a/JsClients/PAIR/scripts/install.ts b/Scripts/PAIR/deploy/pairContract.ts similarity index 69% rename from JsClients/PAIR/scripts/install.ts rename to Scripts/PAIR/deploy/pairContract.ts index 700a02f9..c15bae94 100644 --- a/JsClients/PAIR/scripts/install.ts +++ b/Scripts/PAIR/deploy/pairContract.ts @@ -1,7 +1,7 @@ import { config } from "dotenv"; config(); -import { PAIRClient, utils, constants } from "../src"; -import { parseTokenMeta, sleep, getDeploy } from "./utils"; +import { PAIRClient, utils} from "../../../JsClients/PAIR/src"; +import { getDeploy } from "./utils"; import { Keys, @@ -27,15 +27,15 @@ const KEYS = Keys.Ed25519.parseKeyFiles( `${PAIR_MASTER_KEY_PAIR_PATH}/public_key.pem`, `${PAIR_MASTER_KEY_PAIR_PATH}/secret_key.pem` ); + const pair = new PAIRClient( NODE_ADDRESS!, CHAIN_NAME!, EVENT_STREAM_ADDRESS! ); -const test = async () => { +const deploy = async () => { - const installDeployHash = await pair.install( KEYS, PAIR_CONTRACT_NAME!, @@ -45,8 +45,6 @@ const test = async () => { PAIR_TOTAL_SUPPLY!, FACTORY_CONTRACT_PACKAGE!, CALLEE_PACKAGE!, - // KEYS.publicKey, - // KEYS.publicKey, PAIR_INSTALL_PAYMENT_AMOUNT!, PAIR_WASM_PATH! ); @@ -77,28 +75,4 @@ const test = async () => { }; -export const makedeploypaircontract = async ( - FACTORY_CONTRACT_PACKAGE: string, - CALLEE_PACKAGE: string, - signerkey:string, -) => { - - const deployJSON = await pair.makedeployJSON( - signerkey, - PAIR_CONTRACT_NAME!, - PAIR_TOKEN_NAME!, - PAIR_TOKEN_SYMBOL!, - PAIR_DECIMALS!, - PAIR_TOTAL_SUPPLY!, - FACTORY_CONTRACT_PACKAGE!, - CALLEE_PACKAGE!, - PAIR_INSTALL_PAYMENT_AMOUNT!, - PAIR_WASM_PATH! - ); - - console.log(`... Contract make deploy SuccessFull: ${deployJSON}`); - return deployJSON; - -}; - -//test(); +//deploy(); diff --git a/JsClients/PAIR/scripts/installed.ts b/Scripts/PAIR/deploy/pairContractFunctions.ts similarity index 73% rename from JsClients/PAIR/scripts/installed.ts rename to Scripts/PAIR/deploy/pairContractFunctions.ts index 262fc32b..e03c5cf8 100644 --- a/JsClients/PAIR/scripts/installed.ts +++ b/Scripts/PAIR/deploy/pairContractFunctions.ts @@ -1,8 +1,7 @@ import { config } from "dotenv"; config(); -import { PAIRClient, utils, constants } from "../src"; -import { parseTokenMeta, sleep, getDeploy } from "./utils"; -import { request } from 'graphql-request'; +import { PAIRClient, utils} from "../../../JsClients/PAIR/src"; +import { getDeploy } from "./utils"; import { CLValueBuilder, @@ -12,8 +11,6 @@ import { CLPublicKeyType, } from "casper-js-sdk"; -const { PAIREvents } = constants; - const { NODE_ADDRESS, EVENT_STREAM_ADDRESS, @@ -42,58 +39,32 @@ const { MASTER_KEY_PAIR_PATH } = process.env; -// const TOKEN_META = new Map(parseTokenMeta(process.env.TOKEN_META!)); const KEYS = Keys.Ed25519.parseKeyFiles( `${PAIR_MASTER_KEY_PAIR_PATH}/public_key.pem`, `${PAIR_MASTER_KEY_PAIR_PATH}/secret_key.pem` ); -const ROUTERKEYS = Keys.Ed25519.parseKeyFiles( - `${MASTER_KEY_PAIR_PATH}/public_key.pem`, - `${MASTER_KEY_PAIR_PATH}/secret_key.pem` -); + const pair = new PAIRClient( NODE_ADDRESS!, CHAIN_NAME!, EVENT_STREAM_ADDRESS! ); -function splitdata(data:string) -{ - var temp=data.split('('); - var result=temp[1].split(')'); - return result[0]; -} - -const test = async () => { - - // 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 deploy = async () => { - // const contractHash = await utils.getAccountNamedKeyValue( - // accountInfo, - // `${PAIR_CONTRACT_NAME!}_contract_hash` - // ); - - // console.log(`... Contract Hash: ${contractHash}`); + await pair.setContractHash(PAIR_CONTRACT!); - // We don't need hash- prefix so i'm removing it - //await pair.setContractHash(contractHash.slice(5)); - await pair.setContractHash("53a8121f219ad2c6420f007a2016ed320c519579112b81d505cb15715404b264"); - console.log("... Contract Hash:", PAIR_CONTRACT!); - //name - const liquidity = await pair.liquidity(); - console.log(`... Liquidity: ${liquidity}`); + // //name + // const liquidity = await pair.liquidity(); + // console.log(`... Liquidity: ${liquidity}`); // //symbol // const symbol = await pair.symbol(); // console.log(`... Contract symbol: ${symbol}`); - //initialize + // //initialize // const initializeDeployHash = await pair.initialize( // KEYS, // TOKEN0_CONTRACT!, @@ -106,8 +77,7 @@ const test = async () => { // await getDeploy(NODE_ADDRESS!, initializeDeployHash); // console.log("... Token Initialized successfully"); - - //erc20mint + // //erc20mint // const erc20MintToken0DeployHash = await pair.erc20MintMethod( // KEYS, // TOKEN0_CONTRACT!, @@ -125,7 +95,7 @@ const test = async () => { // console.log(`... Balance of account ${KEYS.publicKey.toAccountHashStr()}`); // console.log(`... Balance: ${balance}`); - //erc20mint + // //erc20mint // const erc20MintToken1DeployHash = await pair.erc20MintMethod( // KEYS, // TOKEN1_CONTRACT!, @@ -162,11 +132,11 @@ const test = async () => { // let nonce = await pair.nonce(KEYS.publicKey); // console.log(`... Nonce: ${nonce}`); - //allowance + // //allowance // let allowance = await pair.allowance(KEYS.publicKey, KEYS.publicKey); // console.log(`... Allowance: ${allowance}`); - //erc20_mint + // //erc20_mint // const erc20mint0DeployHash = await pair.erc20Mint( // KEYS, // TOKEN0_CONTRACT!, @@ -178,10 +148,10 @@ const test = async () => { // await getDeploy(NODE_ADDRESS!, erc20mint0DeployHash); // console.log("... Token minted successfully"); - //erc20mint + // //erc20mint // const erc20mint1DeployHash = await pair.erc20Mint_router( // KEYS, - // ROUTERKEYS.publicKey, + // KEYS.publicKey, // "2000", // MINT_PAYMENT_AMOUNT! // ); @@ -203,12 +173,13 @@ const test = async () => { // console.log("... Token minted successfully"); // //balanceof - let balance_router = await pair.balanceOf_router(ROUTERKEYS.publicKey); - console.log(`... Balance: ${balance_router}`); - //balanceof - //await pair.balanceOf(("C83Fc787656Cf682e8C77A542C636bcA1d46d5f8C011B64ADB2c6596eD7E9280").toLowerCase()); - //await pair.balanceOf((PAIR_CONTRACT_PACKAGE!).toLowerCase()); - //console.log(`... Balance: ${balance}`); + // let balance_router = await pair.balanceOf_router(KEYS.publicKey); + // console.log(`... Balance: ${balance_router}`); + + // //balanceof + // await pair.balanceOf(("C83Fc787656Cf682e8C77A542C636bcA1d46d5f8C011B64ADB2c6596eD7E9280").toLowerCase()); + // await pair.balanceOf((PAIR_CONTRACT_PACKAGE!).toLowerCase()); + // console.log(`... Balance: ${balance}`); // //sync // const syncDeployHash = await pair.sync( @@ -221,8 +192,7 @@ const test = async () => { // await getDeploy(NODE_ADDRESS!, syncDeployHash); // console.log("... Sync functionality successfull"); - - //mint + // //mint // const mintDeployHash = await pair.mint( // KEYS, // PAIR_CONTRACT_PACKAGE!, @@ -285,7 +255,7 @@ const test = async () => { // await getDeploy(NODE_ADDRESS!, skimDeployHash); // console.log("... Skim functionality successfull"); - //erc20mint + // //erc20mint // const erc20MintToken0DeployHash = await pair.erc20MintMethod( // KEYS, // PAIR_CONTRACT_PACKAGE!, @@ -298,19 +268,19 @@ const test = async () => { // await getDeploy(NODE_ADDRESS!, erc20MintToken0DeployHash); // console.log("...ERC20 Token minted successfully"); - //erc20mint - // const erc20MintToken1DeployHash = await pair.erc20MintMethod( - // KEYS, - // TOKEN1_CONTRACT!, - // "1000"!, - // MINT_PAYMENT_AMOUNT! - // ); - // console.log("...ERC20 Mint deploy hash: ", erc20MintToken1DeployHash); + // // //erc20mint + // // const erc20MintToken1DeployHash = await pair.erc20MintMethod( + // // KEYS, + // // TOKEN1_CONTRACT!, + // // "1000"!, + // // MINT_PAYMENT_AMOUNT! + // // ); + // // console.log("...ERC20 Mint deploy hash: ", erc20MintToken1DeployHash); - // await getDeploy(NODE_ADDRESS!, erc20MintToken1DeployHash); - // console.log("...ERC20 Token minted successfully"); + // // await getDeploy(NODE_ADDRESS!, erc20MintToken1DeployHash); + // // console.log("...ERC20 Token minted successfully"); - //swap + // //swap // const swapDeployHash = await pair.swap( // KEYS, // "10", @@ -352,34 +322,4 @@ const test = async () => { }; -//test(); - -export const balanceOf = async (contractHash:string, key:string) => { - - console.log(`... Contract Hash: ${contractHash}`); - - // We don't need hash- prefix so i'm removing it - await pair.setContractHash(contractHash); - - //balanceof - let balance = await pair.balanceOf(key); - - console.log(`... Balance: ${balance}`); - - return balance; - -}; -export const allowance = async (contractHash:string, ownerkey:string, spenderkey:string) => { - - console.log(`... Contract Hash: ${contractHash}`); - - // We don't need hash- prefix so i'm removing it - await pair.setContractHash(contractHash); - - let allowance = await pair.allowance(ownerkey,spenderkey); - - console.log(`... Allowance: ${allowance}`); - - return allowance; - -}; \ No newline at end of file +//deploy(); diff --git a/JsClients/PAIR/scripts/utils.ts b/Scripts/PAIR/deploy/utils.ts similarity index 100% rename from JsClients/PAIR/scripts/utils.ts rename to Scripts/PAIR/deploy/utils.ts diff --git a/JsClients/PAIR/wasm/pair-token.wasm b/Scripts/PAIR/wasm/pair-token.wasm old mode 100755 new mode 100644 similarity index 100% rename from JsClients/PAIR/wasm/pair-token.wasm rename to Scripts/PAIR/wasm/pair-token.wasm diff --git a/JsClients/ROUTER/scripts/install.ts b/Scripts/ROUTER/deploy/routerContract.ts similarity index 91% rename from JsClients/ROUTER/scripts/install.ts rename to Scripts/ROUTER/deploy/routerContract.ts index 4ff7ebff..af04f8ca 100644 --- a/JsClients/ROUTER/scripts/install.ts +++ b/Scripts/ROUTER/deploy/routerContract.ts @@ -1,7 +1,7 @@ import { config } from "dotenv"; config(); -import { UniswapRouterClient, utils, constants } from "../src"; -import { parseTokenMeta, sleep, getDeploy } from "./utils"; +import { UniswapRouterClient, utils} from "../../../JsClients/ROUTER/src"; +import { getDeploy } from "./utils"; import { CLValueBuilder, @@ -22,7 +22,7 @@ const { WCSPR_PACKAGE, LIBRARY_PACKAGE, CONTRACT_NAME, - CONTRACT_HASH, + ROUTER_CONTRACT_HASH, INSTALL_PAYMENT_AMOUNT, MINT_ONE_PAYMENT_AMOUNT, MINT_COPIES_PAYMENT_AMOUNT, @@ -49,7 +49,7 @@ const KEYS = Keys.Ed25519.parseKeyFiles( `${MASTER_KEY_PAIR_PATH}secret_key.pem` ); -const test = async () => { +const deploy = async () => { const uniswapRouter = new UniswapRouterClient( NODE_ADDRESS!, @@ -62,7 +62,7 @@ const test = async () => { FACTORY_CONTRACT_PACKAGE!, WCSPR_PACKAGE!, LIBRARY_PACKAGE!, - 'UniSwapRouter1', + CONTRACT_NAME!, INSTALL_PAYMENT_AMOUNT!, WASM_PATH! ); @@ -78,7 +78,6 @@ const test = async () => { console.log(`... Contract installed successfully.`); - let accountInfo = await utils.getAccountInfo(NODE_ADDRESS!, KEYS.publicKey); console.log(`... Account Info: `); console.log(JSON.stringify(accountInfo, null, 2)); @@ -98,4 +97,4 @@ const test = async () => { console.log(`... Package Hash: ${packageHash}`); }; -//test(); +//deploy(); diff --git a/JsClients/ROUTER/scripts/installed.ts b/Scripts/ROUTER/deploy/routerContractFunctions.ts similarity index 79% rename from JsClients/ROUTER/scripts/installed.ts rename to Scripts/ROUTER/deploy/routerContractFunctions.ts index 03ef23c9..9a4e0a60 100644 --- a/JsClients/ROUTER/scripts/installed.ts +++ b/Scripts/ROUTER/deploy/routerContractFunctions.ts @@ -1,8 +1,7 @@ import { config } from "dotenv"; config(); -import { UniswapRouterClient, utils, constants } from "../src"; -import { parseTokenMeta, sleep, getDeploy } from "./utils"; -import { request } from 'graphql-request'; +import { UniswapRouterClient } from "../../../JsClients/ROUTER/src"; +import { sleep, getDeploy } from "./utils"; import { CLValueBuilder, @@ -11,9 +10,6 @@ import { CLAccountHash, CLPublicKeyType, } from "casper-js-sdk"; -import { isCombinedNodeFlagSet } from "tslint"; - -const { RouterEvents } = constants; const { NODE_ADDRESS, @@ -27,7 +23,7 @@ const { WCSPR, LIBRARY, CONTRACT_NAME, - CONTRACT_HASH, + ROUTER_CONTRACT_HASH, INSTALL_PAYMENT_AMOUNT, PAIR_CONTRACT, PAIR_CONTRACT_PACKAGE, @@ -131,7 +127,7 @@ const KEYS = Keys.Ed25519.parseKeyFiles( `${MASTER_KEY_PAIR_PATH}secret_key.pem` ); -const swap_cspr_for_exact_tokens_test = async ( +const swap_cspr_for_exact_tokens_deploy = async ( UniswapRouter: UniswapRouterClient ) => { let paths: string[] = SCFET_PATH!.split(","); @@ -147,7 +143,7 @@ const swap_cspr_for_exact_tokens_test = async ( ); }; -const swap_exact_tokens_for_cspr_test = async ( +const swap_exact_tokens_for_cspr_deploy = async ( UniswapRouter: UniswapRouterClient ) => { let paths: string[] = SETFC_PATH!.split(","); @@ -162,7 +158,7 @@ const swap_exact_tokens_for_cspr_test = async ( ); }; -const swap_tokens_for_exact_cspr_test = async ( +const swap_tokens_for_exact_cspr_deploy = async ( UniswapRouter: UniswapRouterClient ) => { let paths: string[] = STFEC_PATH!.split(","); @@ -177,7 +173,7 @@ const swap_tokens_for_exact_cspr_test = async ( ); }; -const swap_exact_cspr_for_tokens_test = async ( +const swap_exact_cspr_for_tokens_deploy = async ( UniswapRouter: UniswapRouterClient ) => { let paths: string[] = SECFT_PATH!.split(","); @@ -192,7 +188,7 @@ const swap_exact_cspr_for_tokens_test = async ( ); }; -const swap_tokens_for_exact_tokens_test = async ( +const swap_tokens_for_exact_tokens_deploy = async ( UniswapRouter: UniswapRouterClient ) => { let paths: string[] = STFET_PATH!.split(","); @@ -207,7 +203,7 @@ const swap_tokens_for_exact_tokens_test = async ( ); }; -const swap_exact_tokens_for_tokens_test = async ( +const swap_exact_tokens_for_tokens_deploy = async ( UniswapRouter: UniswapRouterClient ) => { let paths: string[] = SETFT_PATH!.split(","); @@ -223,7 +219,7 @@ const swap_exact_tokens_for_tokens_test = async ( ); }; -const remove_liquidity_cspr_with_permit_test = async ( +const remove_liquidity_cspr_with_permit_deploy = async ( UniswapRouter: UniswapRouterClient ) => { let approve_max: boolean = RLWP_APPROVE_MAX! == "true"; @@ -243,7 +239,7 @@ const remove_liquidity_cspr_with_permit_test = async ( INSTALL_PAYMENT_AMOUNT! ); }; -const remove_liquidity_with_permit_test = async ( +const remove_liquidity_with_permit_deploy = async ( uniswapRouter: UniswapRouterClient ) => { let approve_max: boolean = RLWP_APPROVE_MAX! == "true"; @@ -265,7 +261,7 @@ const remove_liquidity_with_permit_test = async ( ); }; -const add_liquidity_test = async (uniswapRouter: UniswapRouterClient) => { +const add_liquidity_deploy = async (uniswapRouter: UniswapRouterClient) => { return await uniswapRouter.add_liquidity( KEYS, TOKEN_A!, @@ -281,7 +277,7 @@ const add_liquidity_test = async (uniswapRouter: UniswapRouterClient) => { ); }; -const add_liquidity_cspr_test = async (uniswapRouter: UniswapRouterClient) => { +const add_liquidity_cspr_deploy = async (uniswapRouter: UniswapRouterClient) => { return await uniswapRouter.add_liquidity_cspr( KEYS, TOKEN!, @@ -295,7 +291,7 @@ const add_liquidity_cspr_test = async (uniswapRouter: UniswapRouterClient) => { ); }; -const remove_liquidity_test = async (uniswapRouter: UniswapRouterClient) => { +const remove_liquidity_deploy = async (uniswapRouter: UniswapRouterClient) => { return await uniswapRouter.remove_liquidity( KEYS, RL_TOKEN_A!, @@ -308,7 +304,7 @@ const remove_liquidity_test = async (uniswapRouter: UniswapRouterClient) => { INSTALL_PAYMENT_AMOUNT! ); }; -const remove_liquidity_cspr_test = async ( +const remove_liquidity_cspr_deploy = async ( uniswapRouter: UniswapRouterClient ) => { return await uniswapRouter.remove_liquidity_cspr( @@ -324,7 +320,7 @@ const remove_liquidity_cspr_test = async ( }; const add_liquidity = async (uniswapRouter: UniswapRouterClient) => { - const installDeployHash = await add_liquidity_test(uniswapRouter); + const installDeployHash = await add_liquidity_deploy(uniswapRouter); console.log(`... add_liquidity deployHash: ${installDeployHash}\n`); await getDeploy(NODE_ADDRESS!, installDeployHash); @@ -332,7 +328,7 @@ const add_liquidity = async (uniswapRouter: UniswapRouterClient) => { }; const add_liquidity_cspr = async (uniswapRouter: UniswapRouterClient) => { - const installDeployHash = await add_liquidity_cspr_test(uniswapRouter); + const installDeployHash = await add_liquidity_cspr_deploy(uniswapRouter); console.log(`... add_liquidity_cspr deployHash: ${installDeployHash}\n`); await getDeploy(NODE_ADDRESS!, installDeployHash); @@ -340,7 +336,7 @@ const add_liquidity_cspr = async (uniswapRouter: UniswapRouterClient) => { }; const remove_liquidity = async (uniswapRouter: UniswapRouterClient) => { - const installDeployHash = await remove_liquidity_test(uniswapRouter); + const installDeployHash = await remove_liquidity_deploy(uniswapRouter); console.log(`... remove_liquidity deployHash: ${installDeployHash}\n`); await getDeploy(NODE_ADDRESS!, installDeployHash); @@ -348,7 +344,7 @@ const remove_liquidity = async (uniswapRouter: UniswapRouterClient) => { }; const remove_liquidity_cspr = async (uniswapRouter: UniswapRouterClient) => { - const installDeployHash = await remove_liquidity_cspr_test(uniswapRouter); + const installDeployHash = await remove_liquidity_cspr_deploy(uniswapRouter); console.log(`... remove_liquidity_cspr deployHash: ${installDeployHash}\n`); await getDeploy(NODE_ADDRESS!, installDeployHash); @@ -358,7 +354,7 @@ const remove_liquidity_cspr = async (uniswapRouter: UniswapRouterClient) => { const remove_liquidity_with_permit = async ( uniswapRouter: UniswapRouterClient ) => { - const installDeployHash = await remove_liquidity_with_permit_test( + const installDeployHash = await remove_liquidity_with_permit_deploy( uniswapRouter ); console.log( @@ -372,7 +368,7 @@ const remove_liquidity_with_permit = async ( const remove_liquidity_cspr_with_permit = async ( uniswapRouter: UniswapRouterClient ) => { - const installDeployHash = await remove_liquidity_cspr_with_permit_test( + const installDeployHash = await remove_liquidity_cspr_with_permit_deploy( uniswapRouter ); console.log( @@ -386,7 +382,7 @@ const remove_liquidity_cspr_with_permit = async ( const swap_exact_tokens_for_tokens = async ( uniswapRouter: UniswapRouterClient ) => { - const installDeployHash = await swap_exact_tokens_for_tokens_test( + const installDeployHash = await swap_exact_tokens_for_tokens_deploy( uniswapRouter ); console.log( @@ -401,7 +397,7 @@ const swap_exact_tokens_for_tokens = async ( const swap_tokens_for_exact_tokens = async ( uniswapRouter: UniswapRouterClient ) => { - const installDeployHash = await swap_tokens_for_exact_tokens_test( + const installDeployHash = await swap_tokens_for_exact_tokens_deploy( uniswapRouter ); console.log( @@ -415,7 +411,7 @@ const swap_tokens_for_exact_tokens = async ( const swap_exact_cspr_for_tokens = async ( uniswapRouter: UniswapRouterClient ) => { - const installDeployHash = await swap_exact_cspr_for_tokens_test( + const installDeployHash = await swap_exact_cspr_for_tokens_deploy( uniswapRouter ); console.log( @@ -429,7 +425,7 @@ const swap_exact_cspr_for_tokens = async ( const swap_tokens_for_exact_cspr = async ( uniswapRouter: UniswapRouterClient ) => { - const installDeployHash = await swap_tokens_for_exact_cspr_test( + const installDeployHash = await swap_tokens_for_exact_cspr_deploy( uniswapRouter ); console.log( @@ -443,7 +439,7 @@ const swap_tokens_for_exact_cspr = async ( const swap_exact_tokens_for_cspr = async ( uniswapRouter: UniswapRouterClient ) => { - const installDeployHash = await swap_exact_tokens_for_cspr_test( + const installDeployHash = await swap_exact_tokens_for_cspr_deploy( uniswapRouter ); console.log( @@ -457,7 +453,7 @@ const swap_exact_tokens_for_cspr = async ( const swap_cspr_for_exact_tokens = async ( uniswapRouter: UniswapRouterClient ) => { - const installDeployHash = await swap_cspr_for_exact_tokens_test( + const installDeployHash = await swap_cspr_for_exact_tokens_deploy( uniswapRouter ); console.log( @@ -475,44 +471,44 @@ const uniswapRouter = new UniswapRouterClient( EVENT_STREAM_ADDRESS! ); -const test = async () => { +const deploy = async () => { - await uniswapRouter.setContractHash(CONTRACT_HASH!); + await uniswapRouter.setContractHash(ROUTER_CONTRACT_HASH!); - // Test add_liquidity + // Deploy add_liquidity await add_liquidity(uniswapRouter); - // Test add_liquidity_cspr + // Deploy add_liquidity_cspr //add_liquidity_cspr(uniswapRouter); - // Test remove_liquidity + // Deploy remove_liquidity // remove_liquidity(uniswapRouter); - // Test remove_liquidity_cspr + // Deploy remove_liquidity_cspr //remove_liquidity_cspr(uniswapRouter); - // Test remove_liquidity_with_permit + // Deploy remove_liquidity_with_permit //remove_liquidity_with_permit(uniswapRouter); - // Test remove_liquidity_cspr_with_permit + // Deploy remove_liquidity_cspr_with_permit //remove_liquidity_cspr_with_permit(uniswapRouter); - // Test swap_exact_tokens_for_tokens + // Deploy swap_exact_tokens_for_tokens //swap_exact_tokens_for_tokens(uniswapRouter); - // Test swap_tokens_for_exact_tokens + // Deploy swap_tokens_for_exact_tokens //swap_tokens_for_exact_tokens(uniswapRouter); - // Test swap_exact_cspr_for_tokens + // Deploy swap_exact_cspr_for_tokens //swap_exact_cspr_for_tokens(uniswapRouter); - // Test swap_tokens_for_exact_cspr + // Deploy swap_tokens_for_exact_cspr //swap_tokens_for_exact_cspr(uniswapRouter); - // Test swap_exact_tokens_for_cspr + // Deploy swap_exact_tokens_for_cspr //swap_exact_tokens_for_cspr(uniswapRouter); - //Test swap_cspr_for_exact_tokens + // Deploy swap_cspr_for_exact_tokens // swap_cspr_for_exact_tokens(uniswapRouter); // let register = await uniswapRouter.registerWebHook( @@ -529,31 +525,4 @@ const test = async () => { }; -//test(); - -export const swapforinterface = async ( - signerkey:string, - amountin: string, - amountout: string, - paths:string[], - to:string, - deadline:string, - installpaymentamount:string -) => { - - await uniswapRouter.setContractHash(CONTRACT_HASH!); - console.log("key:",signerkey); - const deploy = await uniswapRouter.swap_exact_tokens_for_tokensinterface( - signerkey, - amountin, - amountout, - paths, - to, - deadline, - installpaymentamount - ); - - console.log(`... Swap make deploy SuccessFull: ${deploy}`); - return deploy; - -}; \ No newline at end of file +//deploy(); diff --git a/JsClients/ROUTER/scripts/utils.ts b/Scripts/ROUTER/deploy/utils.ts similarity index 100% rename from JsClients/ROUTER/scripts/utils.ts rename to Scripts/ROUTER/deploy/utils.ts diff --git a/JsClients/ROUTER/wasm/purse-proxy.wasm b/Scripts/ROUTER/wasm/purse-proxy.wasm similarity index 100% rename from JsClients/ROUTER/wasm/purse-proxy.wasm rename to Scripts/ROUTER/wasm/purse-proxy.wasm diff --git a/JsClients/ROUTER/wasm/uniswap-v2-router.wasm b/Scripts/ROUTER/wasm/uniswap-v2-router.wasm similarity index 100% rename from JsClients/ROUTER/wasm/uniswap-v2-router.wasm rename to Scripts/ROUTER/wasm/uniswap-v2-router.wasm diff --git a/graphql/dayUpdates.js b/graphql/dayUpdates.js index feeeacc7..c3213c4a 100644 --- a/graphql/dayUpdates.js +++ b/graphql/dayUpdates.js @@ -1,3 +1,4 @@ +require("dotenv").config(); const UniswapFactory = require("../models/uniswapFactory"); const PairDayData = require("../models/pairDayData"); const PairHourData = require("../models/pairHourData"); @@ -173,8 +174,8 @@ async function updateTokenDayData(token, timeStamp) { BigInt(tokendata.totalLiquidity) * BigInt(tokendata.derivedETH) ).toString(), totalLiquidityUSD: ( - BigInt(tokendata.totalLiquidity) * - BigInt(tokendata.derivedETH) * + (BigInt(tokendata.totalLiquidity) * + BigInt(tokendata.derivedETH)) * BigInt(bundle.ethPrice) ).toString(), dailyTxns: ONE_BI, diff --git a/graphql/helpers.js b/graphql/helpers.js index bf7119b9..544bce1e 100644 --- a/graphql/helpers.js +++ b/graphql/helpers.js @@ -1,4 +1,4 @@ -var ERC20 = require("../JsClients/ERC20/scripts/installed.ts"); +var ERC20 = require("../JsClients/ERC20/erc20FunctionsForBackend/functions"); //var TokenDefinition = require('./tokenDefinition'); const User = require("../models/user"); diff --git a/graphql/mutations.js b/graphql/mutations.js index 20f192c8..1e1b6817 100644 --- a/graphql/mutations.js +++ b/graphql/mutations.js @@ -52,7 +52,7 @@ const { updateTokenDayData, } = require("./dayUpdates"); -var PairContract = require("../JsClients/PAIR/scripts/installed.ts"); +var PairContract = require("../JsClients/PAIR/pairFunctionsForBackend/functions"); const { getEthPriceInUSD, @@ -129,17 +129,13 @@ const handleNewPair = { let TokenName=await fetchTokenName(token0Data.contractHash); let TokenSymbol=await fetchTokenSymbol(token0Data.contractHash); let TokenTotalSupply=BigInt(await fetchTokenTotalSupply(token0Data.contractHash)); - //let TokenTotalSupply = BigInt(1000000000000); token0 = new Token({ id: args.token0, symbol: TokenSymbol, name: TokenName, - //symbol: "WISE", - //name: "WISE", totalSupply: TokenTotalSupply.toString(), decimals: Decimals, - //decimals: 9, derivedETH: ZERO_BD, tradeVolume: ZERO_BD, tradeVolumeUSD: ZERO_BD, @@ -162,17 +158,13 @@ const handleNewPair = { let TokenName=await fetchTokenName(token1Data.contractHash); let TokenSymbol=await fetchTokenSymbol(token1Data.contractHash); let TokenTotalSupply=await fetchTokenTotalSupply(token1Data.contractHash); - //let TokenTotalSupply = BigInt(500000000000); token1 = new Token({ id: args.token1, symbol: TokenSymbol, name: TokenName, - //symbol: "WCSPR", - //name: "WCSPR", totalSupply: TokenTotalSupply.toString(), decimals: Decimals, - //decimals: 9, derivedETH: ZERO_BD, tradeVolume: ZERO_BD, tradeVolumeUSD: ZERO_BD, @@ -904,8 +896,8 @@ const handleSync = { // use derived amounts within pair pair.trackedReserveETH = trackedLiquidityETH.toString(); pair.reserveETH = ( - BigInt(pair.reserve0) * BigInt(token0.derivedETH) + - BigInt(pair.reserve1) * BigInt(token1.derivedETH) + (BigInt(pair.reserve0) * BigInt(token0.derivedETH)) + + (BigInt(pair.reserve1) * BigInt(token1.derivedETH)) ).toString(); pair.reserveUSD = ( BigInt(pair.reserveETH) * BigInt(bundle.ethPrice) @@ -995,14 +987,14 @@ const handleMint = { // get new amounts of USD and ETH for tracking let bundle = await Bundle.findOne({ id: "1" }); let amountTotalUSD = ( - (BigInt(token1.derivedETH) * BigInt(token1Amount) + - BigInt(token0.derivedETH) * BigInt(token0Amount)) * + ((BigInt(token1.derivedETH) * BigInt(token1Amount)) + + (BigInt(token0.derivedETH) * BigInt(token0Amount))) * BigInt(bundle.ethPrice) ).toString(); // update txn counts - pair.txCount = (BigInt(pair.txCount) - BigInt(ONE_BI)).toString(); - uniswap.txCount = (BigInt(uniswap.txCount) - BigInt(ONE_BI)).toString(); + pair.txCount = (BigInt(pair.txCount) + BigInt(ONE_BI)).toString(); + uniswap.txCount = (BigInt(uniswap.txCount) + BigInt(ONE_BI)).toString(); // save entities await token0.save(); @@ -1130,8 +1122,8 @@ const handleBurn = { // get new amounts of USD and ETH for tracking let bundle = await Bundle.findOne({ id: "1" }); let amountTotalUSD = ( - (BigInt(token1.derivedETH) * BigInt(token1Amount) + - BigInt(token0.derivedETH) * BigInt(token0Amount)) * + ((BigInt(token1.derivedETH) * BigInt(token1Amount)) + + (BigInt(token0.derivedETH) * BigInt(token0Amount))) * BigInt(bundle.ethPrice) ).toString(); @@ -1252,8 +1244,8 @@ const handleSwap = { // get total amounts of derived USD and ETH for tracking let derivedAmountETH = - (BigInt(token1.derivedETH) * amount1Total + - BigInt(token0.derivedETH) * amount0Total) / + ((BigInt(token1.derivedETH) * amount1Total) + + (BigInt(token0.derivedETH) * amount0Total)) / BigInt(2); let derivedAmountUSD = derivedAmountETH * BigInt(bundle.ethPrice); @@ -1276,8 +1268,8 @@ const handleSwap = { // update token0 global volume and token liquidity stats token0.tradeVolume = ( BigInt(token0.tradeVolume) + - BigInt(amount0In) + - BigInt(amount0Out) + (BigInt(amount0In) + + BigInt(amount0Out)) ).toString(); token0.tradeVolumeUSD = ( BigInt(token0.tradeVolumeUSD) + trackedAmountUSD @@ -1289,8 +1281,8 @@ const handleSwap = { // update token1 global volume and token liquidity stats token1.tradeVolume = ( BigInt(token1.tradeVolume) + - BigInt(amount1In) + - BigInt(amount1Out) + (BigInt(amount1In) + + BigInt(amount1Out)) ).toString(); token1.tradeVolumeUSD = ( BigInt(token1.tradeVolumeUSD) + trackedAmountUSD @@ -1459,11 +1451,11 @@ const handleSwap = { ).toString(); token0DayData.dailyVolumeETH = ( BigInt(token0DayData.dailyVolumeETH) + - amount0Total * BigInt(token0.derivedETH) + (amount0Total * BigInt(token0.derivedETH)) ).toString(); token0DayData.dailyVolumeUSD = ( BigInt(token0DayData.dailyVolumeUSD) + - amount0Total * BigInt(token0.derivedETH) * BigInt(bundle.ethPrice) + ((amount0Total * BigInt(token0.derivedETH)) * BigInt(bundle.ethPrice)) ).toString(); await token0DayData.save(); @@ -1473,11 +1465,11 @@ const handleSwap = { ).toString(); token1DayData.dailyVolumeETH = ( BigInt(token1DayData.dailyVolumeETH) + - amount1Total * BigInt(token1.derivedETH) + (amount1Total * BigInt(token1.derivedETH)) ).toString(); token1DayData.dailyVolumeUSD = ( BigInt(token1DayData.dailyVolumeUSD) + - amount1Total * BigInt(token1.derivedETH) * BigInt(bundle.ethPrice) + ((amount1Total * BigInt(token1.derivedETH)) * BigInt(bundle.ethPrice)) ).toString(); await token1DayData.save(); diff --git a/graphql/pricing.js b/graphql/pricing.js index 538783cc..8ed6c755 100644 --- a/graphql/pricing.js +++ b/graphql/pricing.js @@ -1,7 +1,7 @@ const Pair = require("../models/pair"); const Token = require("../models/token"); const Bundle = require("../models/bundle"); -var factory = require("../JsClients/FACTORY/scripts/installed.ts"); +var factory = require("../JsClients/FACTORY/factoryFunctionsForBackend/functions"); require("dotenv").config(); const { @@ -36,9 +36,9 @@ async function getEthPriceInUSD() { let usdcWeight = BigInt(usdcPair.reserve1) / totalLiquidityETH; let usdtWeight = BigInt(usdtPair.reserve0) / totalLiquidityETH; return ( - BigInt(daiPair.token0Price) * daiWeight + - BigInt(usdcPair.token0Price) * usdcWeight + - BigInt(usdtPair.token1Price) * usdtWeight + (BigInt(daiPair.token0Price) * daiWeight) + + (BigInt(usdcPair.token0Price) * usdcWeight) + + (BigInt(usdtPair.token1Price) * usdtWeight) ).toString(); // dai and USDC have been created } else if (daiPair !== null && usdcPair !== null) { @@ -47,8 +47,8 @@ async function getEthPriceInUSD() { let daiWeight = BigInt(daiPair.reserve1) / totalLiquidityETH; let usdcWeight = BigInt(usdcPair.reserve1) / totalLiquidityETH; return ( - BigInt(daiPair.token0Price) * daiWeight + - BigInt(usdcPair.token0Price) * usdcWeight + (BigInt(daiPair.token0Price) * daiWeight) + + (BigInt(usdcPair.token0Price) * usdcWeight) ).toString(); // USDC is the only pair so far } else if (usdcPair !== null) { @@ -157,7 +157,7 @@ async function getTrackedVolumeUSD( // both are whitelist tokens, take average of both amounts if (WHITELIST.includes(token0.id) && WHITELIST.includes(token1.id)) { - return (tokenAmount0 * price0 + tokenAmount1 * price1) / BigInt(2); + return ((tokenAmount0 * price0) + (tokenAmount1 * price1)) / BigInt(2); } // take full value of the whitelisted token amount @@ -192,7 +192,7 @@ async function getTrackedLiquidityUSD( // both are whitelist tokens, take average of both amounts if (WHITELIST.includes(token0.id) && WHITELIST.includes(token1.id)) { - return BigInt(tokenAmount0) * price0 + BigInt(tokenAmount1) * price1; + return (BigInt(tokenAmount0) * price0) + (BigInt(tokenAmount1) * price1); } // take double value of the whitelisted token amount diff --git a/package-lock.json b/package-lock.json index 25a588c4..eff720fd 100644 --- a/package-lock.json +++ b/package-lock.json @@ -302,6 +302,19 @@ "integrity": "sha512-ZnQMnLV4e7hDlUvw8H+U8ASL02SS2Gn6+9Ac3wGGLIe7+je2AeAOxPY+izIPJDfFDb7eDjev0Us8MO1iFRN8hA==", "peer": true }, + "node_modules/@jridgewell/gen-mapping": { + "version": "0.3.1", + "resolved": "https://registry.npmjs.org/@jridgewell/gen-mapping/-/gen-mapping-0.3.1.tgz", + "integrity": "sha512-GcHwniMlA2z+WFPWuY8lp3fsza0I8xPFMWL5+n8LYyP6PSvPrXf4+n8stDHZY2DM0zy9sVkRDy1jDI4XGzYVqg==", + "dependencies": { + "@jridgewell/set-array": "^1.0.0", + "@jridgewell/sourcemap-codec": "^1.4.10", + "@jridgewell/trace-mapping": "^0.3.9" + }, + "engines": { + "node": ">=6.0.0" + } + }, "node_modules/@jridgewell/resolve-uri": { "version": "3.0.7", "resolved": "https://registry.npmjs.org/@jridgewell/resolve-uri/-/resolve-uri-3.0.7.tgz", @@ -310,6 +323,23 @@ "node": ">=6.0.0" } }, + "node_modules/@jridgewell/set-array": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/@jridgewell/set-array/-/set-array-1.1.1.tgz", + "integrity": "sha512-Ct5MqZkLGEXTVmQYbGtx9SVqD2fqwvdubdps5D3djjAkgkKwT918VNOz65pEHFaYTeWcukmJmH5SwsA9Tn2ObQ==", + "engines": { + "node": ">=6.0.0" + } + }, + "node_modules/@jridgewell/source-map": { + "version": "0.3.2", + "resolved": "https://registry.npmjs.org/@jridgewell/source-map/-/source-map-0.3.2.tgz", + "integrity": "sha512-m7O9o2uR8k2ObDysZYzdfhb08VuEml5oWGiosa1VdaPZ/A6QyPkAJuwN0Q1lhULOf6B7MtQmHENS743hWtCrgw==", + "dependencies": { + "@jridgewell/gen-mapping": "^0.3.0", + "@jridgewell/trace-mapping": "^0.3.9" + } + }, "node_modules/@jridgewell/sourcemap-codec": { "version": "1.4.13", "resolved": "https://registry.npmjs.org/@jridgewell/sourcemap-codec/-/sourcemap-codec-1.4.13.tgz", @@ -3551,11 +3581,6 @@ "resolved": "https://registry.npmjs.org/lodash.once/-/lodash.once-4.1.1.tgz", "integrity": "sha512-Sb487aTOCr9drQVL8pIxOzVhafOjZN9UU54hiN8PU3uAiSV7lx1yYNpbNmex2PK6dSJoNTSJUUswT651yww3Mg==" }, - "node_modules/lodash.sortby": { - "version": "4.7.0", - "resolved": "https://registry.npmjs.org/lodash.sortby/-/lodash.sortby-4.7.0.tgz", - "integrity": "sha512-HDWXG8isMntAyRF5vZ7xKuEvOhT4AhlRt/3czTSjvGUxjYCBVRQY48ViDHyfYz9VIoBkW4TMGQNapx+l3RUwdA==" - }, "node_modules/longest": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/longest/-/longest-1.0.1.tgz", @@ -5080,13 +5105,13 @@ } }, "node_modules/terser": { - "version": "5.13.1", - "resolved": "https://registry.npmjs.org/terser/-/terser-5.13.1.tgz", - "integrity": "sha512-hn4WKOfwnwbYfe48NgrQjqNOH9jzLqRcIfbYytOXCOv46LBfWr9bDS17MQqOi+BWGD0sJK3Sj5NC/gJjiojaoA==", + "version": "5.14.0", + "resolved": "https://registry.npmjs.org/terser/-/terser-5.14.0.tgz", + "integrity": "sha512-JC6qfIEkPBd9j1SMO3Pfn+A6w2kQV54tv+ABQLgZr7dA3k/DL/OBoYSWxzVpZev3J+bUHXfr55L8Mox7AaNo6g==", "dependencies": { + "@jridgewell/source-map": "^0.3.2", "acorn": "^8.5.0", "commander": "^2.20.0", - "source-map": "~0.8.0-beta.0", "source-map-support": "~0.5.20" }, "bin": { @@ -5153,40 +5178,6 @@ "resolved": "https://registry.npmjs.org/commander/-/commander-2.20.3.tgz", "integrity": "sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ==" }, - "node_modules/terser/node_modules/source-map": { - "version": "0.8.0-beta.0", - "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.8.0-beta.0.tgz", - "integrity": "sha512-2ymg6oRBpebeZi9UUNsgQ89bhx01TcTkmNTGnNO88imTmbSgy4nfujrgVEFKWpMTEGA11EDkTt7mqObTPdigIA==", - "dependencies": { - "whatwg-url": "^7.0.0" - }, - "engines": { - "node": ">= 8" - } - }, - "node_modules/terser/node_modules/tr46": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/tr46/-/tr46-1.0.1.tgz", - "integrity": "sha1-qLE/1r/SSJUZZ0zN5VujaTtwbQk=", - "dependencies": { - "punycode": "^2.1.0" - } - }, - "node_modules/terser/node_modules/webidl-conversions": { - "version": "4.0.2", - "resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-4.0.2.tgz", - "integrity": "sha512-YQ+BmxuTgd6UXZW3+ICGfyqRyHXVlD5GtQr5+qjiNW7bF0cqrzX500HVXPBOvgXb5YnzDd+h0zqyv61KUD7+Sg==" - }, - "node_modules/terser/node_modules/whatwg-url": { - "version": "7.1.0", - "resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-7.1.0.tgz", - "integrity": "sha512-WUu7Rg1DroM7oQvGWfOiAK21n74Gg+T4elXEQYkOhtyLeWiJFoOGLXPKI/9gzIie9CtwVLm8wtw6YJdKyxSjeg==", - "dependencies": { - "lodash.sortby": "^4.7.0", - "tr46": "^1.0.1", - "webidl-conversions": "^4.0.2" - } - }, "node_modules/text-table": { "version": "0.2.0", "resolved": "https://registry.npmjs.org/text-table/-/text-table-0.2.0.tgz", @@ -6274,11 +6265,35 @@ "integrity": "sha512-ZnQMnLV4e7hDlUvw8H+U8ASL02SS2Gn6+9Ac3wGGLIe7+je2AeAOxPY+izIPJDfFDb7eDjev0Us8MO1iFRN8hA==", "peer": true }, + "@jridgewell/gen-mapping": { + "version": "0.3.1", + "resolved": "https://registry.npmjs.org/@jridgewell/gen-mapping/-/gen-mapping-0.3.1.tgz", + "integrity": "sha512-GcHwniMlA2z+WFPWuY8lp3fsza0I8xPFMWL5+n8LYyP6PSvPrXf4+n8stDHZY2DM0zy9sVkRDy1jDI4XGzYVqg==", + "requires": { + "@jridgewell/set-array": "^1.0.0", + "@jridgewell/sourcemap-codec": "^1.4.10", + "@jridgewell/trace-mapping": "^0.3.9" + } + }, "@jridgewell/resolve-uri": { "version": "3.0.7", "resolved": "https://registry.npmjs.org/@jridgewell/resolve-uri/-/resolve-uri-3.0.7.tgz", "integrity": "sha512-8cXDaBBHOr2pQ7j77Y6Vp5VDT2sIqWyWQ56TjEq4ih/a4iST3dItRe8Q9fp0rrIl9DoKhWQtUQz/YpOxLkXbNA==" }, + "@jridgewell/set-array": { + "version": "1.1.1", + "resolved": "https://registry.npmjs.org/@jridgewell/set-array/-/set-array-1.1.1.tgz", + "integrity": "sha512-Ct5MqZkLGEXTVmQYbGtx9SVqD2fqwvdubdps5D3djjAkgkKwT918VNOz65pEHFaYTeWcukmJmH5SwsA9Tn2ObQ==" + }, + "@jridgewell/source-map": { + "version": "0.3.2", + "resolved": "https://registry.npmjs.org/@jridgewell/source-map/-/source-map-0.3.2.tgz", + "integrity": "sha512-m7O9o2uR8k2ObDysZYzdfhb08VuEml5oWGiosa1VdaPZ/A6QyPkAJuwN0Q1lhULOf6B7MtQmHENS743hWtCrgw==", + "requires": { + "@jridgewell/gen-mapping": "^0.3.0", + "@jridgewell/trace-mapping": "^0.3.9" + } + }, "@jridgewell/sourcemap-codec": { "version": "1.4.13", "resolved": "https://registry.npmjs.org/@jridgewell/sourcemap-codec/-/sourcemap-codec-1.4.13.tgz", @@ -8863,11 +8878,6 @@ "resolved": "https://registry.npmjs.org/lodash.once/-/lodash.once-4.1.1.tgz", "integrity": "sha512-Sb487aTOCr9drQVL8pIxOzVhafOjZN9UU54hiN8PU3uAiSV7lx1yYNpbNmex2PK6dSJoNTSJUUswT651yww3Mg==" }, - "lodash.sortby": { - "version": "4.7.0", - "resolved": "https://registry.npmjs.org/lodash.sortby/-/lodash.sortby-4.7.0.tgz", - "integrity": "sha512-HDWXG8isMntAyRF5vZ7xKuEvOhT4AhlRt/3czTSjvGUxjYCBVRQY48ViDHyfYz9VIoBkW4TMGQNapx+l3RUwdA==" - }, "longest": { "version": "1.0.1", "resolved": "https://registry.npmjs.org/longest/-/longest-1.0.1.tgz", @@ -10020,13 +10030,13 @@ } }, "terser": { - "version": "5.13.1", - "resolved": "https://registry.npmjs.org/terser/-/terser-5.13.1.tgz", - "integrity": "sha512-hn4WKOfwnwbYfe48NgrQjqNOH9jzLqRcIfbYytOXCOv46LBfWr9bDS17MQqOi+BWGD0sJK3Sj5NC/gJjiojaoA==", + "version": "5.14.0", + "resolved": "https://registry.npmjs.org/terser/-/terser-5.14.0.tgz", + "integrity": "sha512-JC6qfIEkPBd9j1SMO3Pfn+A6w2kQV54tv+ABQLgZr7dA3k/DL/OBoYSWxzVpZev3J+bUHXfr55L8Mox7AaNo6g==", "requires": { + "@jridgewell/source-map": "^0.3.2", "acorn": "^8.5.0", "commander": "^2.20.0", - "source-map": "~0.8.0-beta.0", "source-map-support": "~0.5.20" }, "dependencies": { @@ -10039,37 +10049,6 @@ "version": "2.20.3", "resolved": "https://registry.npmjs.org/commander/-/commander-2.20.3.tgz", "integrity": "sha512-GpVkmM8vF2vQUkj2LvZmD35JxeJOLCwJ9cUkugyk2nuhbv3+mJvpLYYt+0+USMxE+oj+ey/lJEnhZw75x/OMcQ==" - }, - "source-map": { - "version": "0.8.0-beta.0", - "resolved": "https://registry.npmjs.org/source-map/-/source-map-0.8.0-beta.0.tgz", - "integrity": "sha512-2ymg6oRBpebeZi9UUNsgQ89bhx01TcTkmNTGnNO88imTmbSgy4nfujrgVEFKWpMTEGA11EDkTt7mqObTPdigIA==", - "requires": { - "whatwg-url": "^7.0.0" - } - }, - "tr46": { - "version": "1.0.1", - "resolved": "https://registry.npmjs.org/tr46/-/tr46-1.0.1.tgz", - "integrity": "sha1-qLE/1r/SSJUZZ0zN5VujaTtwbQk=", - "requires": { - "punycode": "^2.1.0" - } - }, - "webidl-conversions": { - "version": "4.0.2", - "resolved": "https://registry.npmjs.org/webidl-conversions/-/webidl-conversions-4.0.2.tgz", - "integrity": "sha512-YQ+BmxuTgd6UXZW3+ICGfyqRyHXVlD5GtQr5+qjiNW7bF0cqrzX500HVXPBOvgXb5YnzDd+h0zqyv61KUD7+Sg==" - }, - "whatwg-url": { - "version": "7.1.0", - "resolved": "https://registry.npmjs.org/whatwg-url/-/whatwg-url-7.1.0.tgz", - "integrity": "sha512-WUu7Rg1DroM7oQvGWfOiAK21n74Gg+T4elXEQYkOhtyLeWiJFoOGLXPKI/9gzIie9CtwVLm8wtw6YJdKyxSjeg==", - "requires": { - "lodash.sortby": "^4.7.0", - "tr46": "^1.0.1", - "webidl-conversions": "^4.0.2" - } } } }, diff --git a/package.json b/package.json index a8b97acf..aae19251 100644 --- a/package.json +++ b/package.json @@ -4,14 +4,14 @@ "private": true, "scripts": { "start": "ts-node ./bin/www", - "test:erc20install": "ts-node JsClients/ERC20/scripts/install.ts", - "test:erc20installed": "ts-node JsClients/ERC20/scripts/installed.ts", - "test:pairinstall": "ts-node JsClients/PAIR/scripts/install.ts", - "test:pairinstalled": "ts-node JsClients/PAIR/scripts/installed.ts", - "test:factoryinstall": "ts-node JsClients/FACTORY/scripts/install.ts", - "test:factoryinstalled": "ts-node JsClients/FACTORY/scripts/installed.ts", - "test:routerinstall": "ts-node JsClients/ROUTER/scripts/install.ts", - "test:routerinstalled": "ts-node JsClients/ROUTER/scripts/installed.ts" + "deploy:erc20": "ts-node Scripts/ERC20/deploy/erc20Contract.ts", + "deploy:erc20Functions": "ts-node Scripts/ERC20/deploy/erc20ContractFunctions.ts", + "deploy:factory": "ts-node Scripts/FACTORY/deploy/factoryContract.ts", + "deploy:factoryFunctions": "ts-node Scripts/FACTORY/deploy/factoryContractFunctions.ts", + "deploy:pair": "ts-node Scripts/PAIR/deploy/pairContract.ts", + "deploy:pairFunctions": "ts-node Scripts/PAIR/deploy/pairContractFunctions.ts", + "deploy:router": "ts-node Scripts/ROUTER/deploy/routerContract.ts", + "deploy:routerFunctions": "ts-node Scripts/ROUTER/deploy/routerContractFunctions.ts" }, "engine": { "node": "16.14.0", diff --git a/readme.md b/readme.md index fb53c9fb..3ce46356 100644 --- a/readme.md +++ b/readme.md @@ -15,8 +15,6 @@ This graphql dynamically tracks any pair created by the casper uniswap factory. npm install to install the require packages npm start to start the server -Heroku App Link: https://casper-uniswap-v2-graphql.herokuapp.com/ - ## Queries Below are a few ways to show how to query the casper-uniswap-graphql for data. The queries show most of the information that is queryable, but there are many other filtering options that can be used, just check out the [querying api](https://thegraph.com/docs/graphql-api). These queries can be used locally or in The Graph Explorer playground. @@ -61,16 +59,51 @@ This query fetches aggredated data from all Casper uniswap pairs and tokens, to ## Deployment of Contracts -#### Generate key +#### Generate the keys + +Paste this command on the ubuntu terminal, that will create a keys folder for you containing public key , public key hex and secret key. ``` -casper-client keygen key +casper-client keygen keys ``` -#### Paste the key +#### Paste the keys -Paste the key created by the above command to JsClients/ERC20, JsClients/FACTORY, JsClients/PAIR and JsClients/ROUTER. +Paste the keys folder created by the above command to Scripts/ERC20, Scripts/FACTORY, Scripts/PAIR and Scripts/ROUTER folders. #### Fund the key -We can fund the key from casper live website faucet page on testnet. +We can fund the keys from casper live website faucet page on testnet. + + +Use the script file in package.json to perform the deployments +``` +"scripts": { + "deploy:erc20": "ts-node Scripts/ERC20/deploy/erc20Contract.ts", + "deploy:erc20Functions": "ts-node Scripts/ERC20/deploy/erc20ContractFunctions.ts", + "deploy:factory": "ts-node Scripts/FACTORY/deploy/factoryContract.ts", + "deploy:factoryFunctions": "ts-node Scripts/FACTORY/deploy/factoryContractFunctions.ts", + "deploy:pair": "ts-node Scripts/PAIR/deploy/pairContract.ts", + "deploy:pairFunctions": "ts-node Scripts/PAIR/deploy/pairContractFunctions.ts", + "deploy:router": "ts-node Scripts/ROUTER/deploy/routerContract.ts", + "deploy:routerFunctions": "ts-node Scripts/ROUTER/deploy/routerContractFunctions.ts" + }, +``` + +Use the following commands to perform deployments +``` +npm run deploy:erc20 +npm run deploy:erc20Functions + +npm run deploy:factory +npm run deploy:factoryFunctions + +npm run deploy:pair +npm run deploy:pairFunctions + +npm run deploy:router +npm run deploy:routerFunctions + +``` + +* CONFIGURE .env BEFORE and during DEPLOYMENT diff --git a/routes/deploypair.js b/routes/deploypair.js index abc5d71e..03aebf8b 100644 --- a/routes/deploypair.js +++ b/routes/deploypair.js @@ -1,7 +1,7 @@ require("dotenv").config(); var express = require("express"); var router = express.Router(); -var pair = require("../JsClients/PAIR/scripts/install.ts"); +var pair = require("../JsClients/PAIR/pairFunctionsForBackend/functions"); var pairsagainstuser = require("../models/pairsagainstuser"); var pairagainstuser = require("../models/pairagainstuser"); var pairsModel = require("../models/pair"); diff --git a/routes/erc20routes.js b/routes/erc20routes.js index f460e49c..43b23bc1 100644 --- a/routes/erc20routes.js +++ b/routes/erc20routes.js @@ -1,7 +1,7 @@ require("dotenv").config(); var express = require("express"); var router = express.Router(); -var erc20 = require("../JsClients/ERC20/scripts/installed.ts"); +var erc20 = require("../JsClients/ERC20/erc20FunctionsForBackend/functions"); router.route("/balanceagainstuser").post(async function (req, res, next) { try { diff --git a/routes/listenerroutes.js b/routes/listenerroutes.js index fd159753..14afa521 100644 --- a/routes/listenerroutes.js +++ b/routes/listenerroutes.js @@ -6,7 +6,7 @@ var pairModel = require("../models/pair"); var hashesofpairsModel = require("../models/hashesofpairs"); var eventsModel = require("../models/events"); var pairagainstuser = require("../models/pairagainstuser"); -var paircontract = require("../JsClients/PAIR/scripts/installed.ts"); +var paircontract = require("../JsClients/PAIR/pairFunctionsForBackend/functions"); var allcontractsDataModel = require("../models/allcontractsData"); var RemoveReservesDataModel = require("../models/removeReservesData"); diff --git a/routes/pairroutes.js b/routes/pairroutes.js index c2e59d60..d4a93ff6 100644 --- a/routes/pairroutes.js +++ b/routes/pairroutes.js @@ -2,7 +2,7 @@ require("dotenv").config(); var express = require("express"); const { createFalse } = require("typescript"); var router = express.Router(); -var pair = require("../JsClients/PAIR/scripts/installed.ts"); +var pair = require("../JsClients/PAIR/pairFunctionsForBackend/functions"); var AllcontractsData = require("../models/allcontractsData"); router diff --git a/routes/readWasm.js b/routes/readWasm.js index 84518351..d85ee7cf 100644 --- a/routes/readWasm.js +++ b/routes/readWasm.js @@ -6,7 +6,7 @@ var routerJsClient=require('../JsClients/ROUTER/src/utils') router.route("/getWasmData").get(async function (req, res, next) { try { - let wasmData= routerJsClient.getWasmDataInBuffer('JsClients/ROUTER/wasm/purse-proxy.wasm'); + let wasmData= routerJsClient.getWasmDataInBuffer('Scripts/ROUTER/wasm/purse-proxy.wasm'); console.log(wasmData); return res.status(200).json({ @@ -27,7 +27,7 @@ router.route("/getWasmData").get(async function (req, res, next) { router.route("/getWCSPRWasmData").get(async function (req, res, next) { try { - let wasmData= routerJsClient.getWasmDataInBuffer('JsClients/ERC20/wasm/purse-proxy.wasm'); + let wasmData= routerJsClient.getWasmDataInBuffer('Scripts/ERC20/wasm/purse-proxy.wasm'); console.log(wasmData); return res.status(200).json({ diff --git a/routes/swaproutes.js b/routes/swaproutes.js index abab6714..e4893c6d 100644 --- a/routes/swaproutes.js +++ b/routes/swaproutes.js @@ -1,7 +1,7 @@ require("dotenv").config(); var express = require("express"); var router = express.Router(); -var routercontract = require("../JsClients/ROUTER/scripts/installed.ts"); +var routercontract = require("../JsClients/ROUTER/routerFunctionsForBackend/functions"); router.route("/swapmakedeployJSON").post(async function (req, res, next) { try {