From bc9fbd87910d5aedf290eee3a473328e8f7e454e Mon Sep 17 00:00:00 2001 From: Hammad-Mubeen Date: Fri, 31 Dec 2021 01:21:00 +0500 Subject: [PATCH] WCSPR Jsclient removed and ERC20, PAIR, FACTORY and ROUTER Jsclient code cleaned --- JsClients/ERC20/src/erc20.ts | 14 +- JsClients/ERC20/test/installed.ts | 74 -- JsClients/FACTORY/src/factory.ts | 2 +- JsClients/FACTORY/test/installed.ts | 49 -- JsClients/PAIR/src/pair.ts | 25 +- JsClients/PAIR/test/installed.ts | 248 ------- JsClients/ROUTER/src/uniswap-router-client.ts | 55 +- JsClients/WCSPR/keys/public_key.pem | 3 - JsClients/WCSPR/keys/public_key_hex | 1 - JsClients/WCSPR/keys/secret_key.pem | 3 - JsClients/WCSPR/src/constants.ts | 5 - JsClients/WCSPR/src/erc20.ts | 664 ------------------ JsClients/WCSPR/src/index.ts | 9 - JsClients/WCSPR/src/types.d.ts | 9 - JsClients/WCSPR/src/utils.ts | 125 ---- JsClients/WCSPR/test/install.ts | 73 -- JsClients/WCSPR/test/installed.ts | 302 -------- JsClients/WCSPR/test/utils.ts | 34 - 18 files changed, 29 insertions(+), 1666 deletions(-) delete mode 100644 JsClients/WCSPR/keys/public_key.pem delete mode 100644 JsClients/WCSPR/keys/public_key_hex delete mode 100644 JsClients/WCSPR/keys/secret_key.pem delete mode 100644 JsClients/WCSPR/src/constants.ts delete mode 100644 JsClients/WCSPR/src/erc20.ts delete mode 100644 JsClients/WCSPR/src/index.ts delete mode 100644 JsClients/WCSPR/src/types.d.ts delete mode 100644 JsClients/WCSPR/src/utils.ts delete mode 100644 JsClients/WCSPR/test/install.ts delete mode 100644 JsClients/WCSPR/test/installed.ts delete mode 100644 JsClients/WCSPR/test/utils.ts diff --git a/JsClients/ERC20/src/erc20.ts b/JsClients/ERC20/src/erc20.ts index e1897992..d52f3012 100644 --- a/JsClients/ERC20/src/erc20.ts +++ b/JsClients/ERC20/src/erc20.ts @@ -234,7 +234,7 @@ class ERC20Client { }); if (deployHash !== null) { - this.addPendingDeploy(ERC20Events.Approval, deployHash); + return deployHash; } else { throw Error("Invalid Deploy"); @@ -264,7 +264,7 @@ class ERC20Client { }); if (deployHash !== null) { - this.addPendingDeploy(ERC20Events.Transfer, deployHash); + return deployHash; } else { throw Error("Invalid Deploy"); @@ -296,7 +296,7 @@ class ERC20Client { }); if (deployHash !== null) { - this.addPendingDeploy(ERC20Events.Transfer, deployHash); + return deployHash; } else { throw Error("Invalid Deploy"); @@ -325,7 +325,7 @@ class ERC20Client { }); if (deployHash !== null) { - this.addPendingDeploy(ERC20Events.Transfer, deployHash); + return deployHash; } else { throw Error("Invalid Deploy"); @@ -355,7 +355,7 @@ class ERC20Client { // }); // if (deployHash !== null) { - // this.addPendingDeploy(ERC20Events.Transfer, deployHash); + // return deployHash; // } else { // throw Error("Invalid Deploy"); @@ -385,7 +385,7 @@ class ERC20Client { }); if (deployHash !== null) { - this.addPendingDeploy(ERC20Events.Transfer, deployHash); + return deployHash; } else { throw Error("Invalid Deploy"); @@ -423,7 +423,7 @@ class ERC20Client { }); if (deployHash !== null) { - this.addPendingDeploy(ERC20Events.Approval, deployHash); + return deployHash; } else { throw Error("Invalid Deploy"); diff --git a/JsClients/ERC20/test/installed.ts b/JsClients/ERC20/test/installed.ts index c2c0eef7..96bd5db2 100644 --- a/JsClients/ERC20/test/installed.ts +++ b/JsClients/ERC20/test/installed.ts @@ -69,80 +69,6 @@ const erc20 = new ERC20Client( const test = async () => { - // const listener = erc20.onEvent( - // [ - // ERC20Events.Approval, - // ERC20Events.Transfer - // ], - // async (eventName, deploy, result) => { - // if (deploy.success) { - // console.log(`Successfull deploy of: ${eventName}, deployHash: ${deploy.deployHash}`); - // const [timestamp,gasPrice,block_hash]= await getDeploy(NODE_ADDRESS!, deploy.deployHash); - // console.log("... Deployhash: ", deploy.deployHash); - // console.log("... Timestamp: ", timestamp); - // //console.log("... GasPrice: ", gasPrice); - // console.log("... Block hash: ", block_hash); - - // let newData = JSON.parse(JSON.stringify(result.value())); - - // if(eventName=="approve") - // { - // console.log(eventName+ " Event result: "); - // console.log(newData[0][0].data + " = " + newData[0][1].data); - // console.log(newData[1][0].data + " = " + newData[1][1].data); - // console.log(newData[2][0].data + " = " + newData[2][1].data); - // console.log(newData[3][0].data + " = " + newData[3][1].data); - // console.log(newData[4][0].data + " = " + newData[4][1].data); - // } - // else if(eventName=="erc20_transfer") - // { - // console.log(eventName+ " Event result: "); - // console.log(newData[0][0].data + " = " + newData[0][1].data); - // console.log(newData[1][0].data + " = " + newData[1][1].data); - - // console.log(newData[2][0].data + " = " + newData[2][1].data); - // console.log(newData[3][0].data + " = " + newData[3][1].data); - // console.log(newData[4][0].data + " = " + newData[4][1].data); - - // var flag=0; - // var temp=(newData[3][1].data).split('('); - // console.log("temp[0]: ",temp[0]); - // if(temp[0] == "Key::Account(") - // { - // flag=1; - // } - // var from=splitdata(newData[2][1].data); - // var to=splitdata(newData[3][1].data); - // var value=parseInt(newData[4][1].data); - - // console.log("from: ", from); - // console.log("to: ", to); - // console.log("value: ",value); - - // if(flag==0) - // { - // request(GRAPHQL!, - // `mutation handleTransfer( $from: String!, $to: String!, $value: Int!, $pairAddress: String!, $deployHash: String!, $timeStamp: String!, $blockHash: String!){ - // handleTransfer( from: $from, to: $to, value: $value, pairAddress: $pairAddress, deployHash: $deployHash, timeStamp: $timeStamp, blockHash: $blockHash) { - // result - // } - - // }`, - // {from:from, to: to, value: value, pairAddress: to, deployHash:deploy.deployHash,timeStamp:timestamp.toString(), blockHash:block_hash}) - // .then(data => console.log(data)) - // .catch(error => console.error(error)); - // } - - // } - - // } else { - // console.log(`Failed deploy of ${eventName}, deployHash: ${deploy.deployHash}`); - // console.log(`Error: ${deploy.error}`); - // } - // } - // ); - // console.log("listener: ",listener); - await erc20.setContractHash(TOKEN1_CONTRACT!); // // //name diff --git a/JsClients/FACTORY/src/factory.ts b/JsClients/FACTORY/src/factory.ts index 593a8996..7761967d 100644 --- a/JsClients/FACTORY/src/factory.ts +++ b/JsClients/FACTORY/src/factory.ts @@ -244,7 +244,7 @@ class FACTORYClient { }); if (deployHash !== null) { - this.addPendingDeploy(FACTORYEvents.PairCreated, deployHash); + return deployHash; } else { throw Error("Invalid Deploy"); diff --git a/JsClients/FACTORY/test/installed.ts b/JsClients/FACTORY/test/installed.ts index e8bf6938..b83fcd23 100644 --- a/JsClients/FACTORY/test/installed.ts +++ b/JsClients/FACTORY/test/installed.ts @@ -51,55 +51,6 @@ function splitdata(data:string) const test = async () => { - // const listener = factory.onEvent( - // [ - // FACTORYEvents.PairCreated - // ], - // async (eventName, deploy, result) => { - // if (deploy.success) { - // console.log(`Successfull deploy of: ${eventName}, deployHash: ${deploy.deployHash}`); - // const [timestamp,block_hash]= await getDeploy(NODE_ADDRESS!, deploy.deployHash); - // console.log("... Timestamp: ", timestamp); - // console.log("... Block hash: ", block_hash); - // console.log("result.value(): ", result.value()); - // let newData = JSON.parse(JSON.stringify(result.value())); - - // console.log(eventName+ " Event result: "); - // console.log(newData[0][0].data + " = " + newData[0][1].data); - // console.log(newData[1][0].data + " = " + newData[1][1].data); - // console.log(newData[2][0].data + " = " + newData[2][1].data); - // console.log(newData[3][0].data + " = " + newData[3][1].data); - // console.log(newData[4][0].data + " = " + newData[4][1].data); - // console.log(newData[5][0].data + " = " + newData[5][1].data); - - // var allpairslength=parseInt(newData[0][1].data); - // var pair=splitdata(newData[3][1].data); - // var token0=splitdata(newData[4][1].data); - // var token1=splitdata(newData[5][1].data); - - // console.log("allpairslength: ", allpairslength); - // console.log("pair splited: ", pair); - // console.log("token0 splited: ", token0); - // console.log("token1 splited: ", token1); - - // request(GRAPHQL!, - // `mutation handleNewPair( $token0: String!, $token1: String!, $pair: String!, $all_pairs_length: Int!, $timeStamp: String!, $blockHash: String!){ - // handleNewPair( token0: $token0, token1: $token1, pair: $pair, all_pairs_length: $all_pairs_length, timeStamp: $timeStamp, blockHash: $blockHash) { - // result - // } - - // }`, - // {token0:token0, token1:token1, pair: pair, all_pairs_length: allpairslength, timeStamp:timestamp.toString(), blockHash:block_hash}) - // .then(data => console.log(data)) - // .catch(error => console.error(error)); - - // } else { - // console.log(`Failed deploy of ${eventName}, deployHash: ${deploy.deployHash}`); - // console.log(`Error: ${deploy.error}`); - // } - // } - // ); - await sleep(5 * 1000); let accountInfo = await utils.getAccountInfo(NODE_ADDRESS!, KEYS.publicKey); diff --git a/JsClients/PAIR/src/pair.ts b/JsClients/PAIR/src/pair.ts index 31b65b42..76a2272d 100644 --- a/JsClients/PAIR/src/pair.ts +++ b/JsClients/PAIR/src/pair.ts @@ -266,7 +266,7 @@ class PAIRClient { }); if (deployHash !== null) { - this.addPendingDeploy(PAIREvents.Approval, deployHash); + return deployHash; } else { throw Error("Invalid Deploy"); @@ -297,7 +297,7 @@ class PAIRClient { }); if (deployHash !== null) { - this.addPendingDeploy(PAIREvents.Transfer, deployHash); + return deployHash; } else { throw Error("Invalid Deploy"); @@ -329,7 +329,7 @@ class PAIRClient { }); if (deployHash !== null) { - this.addPendingDeploy(PAIREvents.Transfer, deployHash); + return deployHash; } else { throw Error("Invalid Deploy"); @@ -357,8 +357,7 @@ class PAIRClient { }); if (deployHash !== null) { - this.addPendingDeploy(PAIREvents.Sync, deployHash); - this.addPendingDeploy(PAIREvents.Mint, deployHash); + return deployHash; } else { throw Error("Invalid Deploy"); @@ -385,8 +384,7 @@ class PAIRClient { }); if (deployHash !== null) { - this.addPendingDeploy(PAIREvents.Sync, deployHash); - this.addPendingDeploy(PAIREvents.Burn, deployHash); + return deployHash; } else { throw Error("Invalid Deploy"); @@ -424,7 +422,7 @@ class PAIRClient { }); if (deployHash !== null) { - this.addPendingDeploy(PAIREvents.Approval, deployHash); + return deployHash; } else { throw Error("Invalid Deploy"); @@ -481,7 +479,7 @@ class PAIRClient { }); if (deployHash !== null) { - this.addPendingDeploy(PAIREvents.Transfer, deployHash); + return deployHash; } else { throw Error("Invalid Deploy"); @@ -512,7 +510,7 @@ class PAIRClient { }); if (deployHash !== null) { - this.addPendingDeploy(PAIREvents.Transfer, deployHash); + return deployHash; } else { throw Error("Invalid Deploy"); @@ -540,7 +538,7 @@ class PAIRClient { }); if (deployHash !== null) { - this.addPendingDeploy(PAIREvents.Sync, deployHash); + return deployHash; } else { throw Error("Invalid Deploy"); @@ -574,8 +572,7 @@ class PAIRClient { }); if (deployHash !== null) { - this.addPendingDeploy(PAIREvents.Sync, deployHash); - this.addPendingDeploy(PAIREvents.Swap, deployHash); + return deployHash; } else { throw Error("Invalid Deploy"); @@ -641,7 +638,7 @@ class PAIRClient { }); if (deployHash !== null) { - this.addPendingDeploy(PAIREvents.Transfer, deployHash); + return deployHash; } else { throw Error("Invalid Deploy"); diff --git a/JsClients/PAIR/test/installed.ts b/JsClients/PAIR/test/installed.ts index 4d846fee..37a310cd 100644 --- a/JsClients/PAIR/test/installed.ts +++ b/JsClients/PAIR/test/installed.ts @@ -67,254 +67,6 @@ function splitdata(data:string) const test = async () => { - // const listener = pair.onEvent( - // [ - // PAIREvents.Transfer, - // PAIREvents.Mint, - // PAIREvents.Burn, - // PAIREvents.Sync, - // PAIREvents.Swap, - // ], - // async (eventName, deploy, result) => { - // if (deploy.success) { - // console.log(`Successfull deploy of: ${eventName}, deployHash: ${deploy.deployHash}`); - // const [timestamp,block_hash]= await getDeploy(NODE_ADDRESS!, deploy.deployHash); - // console.log("... Deployhash: ", deploy.deployHash); - // console.log("... Timestamp: ", timestamp); - // console.log("... Block hash: ", block_hash); - // console.log("result.value(): ",result.value()); - // let newData = JSON.parse(JSON.stringify(result.value())); - // if(eventName=="approve") - // { - // console.log(eventName+ " Event result: "); - // console.log(newData[0][0].data + " = " + newData[0][1].data); - // console.log(newData[1][0].data + " = " + newData[1][1].data); - // console.log(newData[2][0].data + " = " + newData[2][1].data); - // console.log(newData[3][0].data + " = " + newData[3][1].data); - // console.log(newData[4][0].data + " = " + newData[4][1].data); - // } - // else if(eventName=="erc20_transfer") - // { - // console.log(eventName+ " Event result: "); - // console.log(newData[0][0].data + " = " + newData[0][1].data); - // console.log(newData[1][0].data + " = " + newData[1][1].data); - - // console.log(newData[2][0].data + " = " + newData[2][1].data); - // console.log(newData[3][0].data + " = " + newData[3][1].data); - // console.log(newData[4][0].data + " = " + newData[4][1].data); - - // var flag=0; - // var temp=(newData[3][1].data).split('('); - // console.log("temp[0]: ",temp[0]); - // if(temp[0] == "Key::Account(") - // { - // flag=1; - // } - // var from=splitdata(newData[2][1].data); - // var to=splitdata(newData[3][1].data); - // var value=parseInt(newData[4][1].data); - - // console.log("from: ", from); - // console.log("to: ", to); - // console.log("value: ",value); - - // if(flag==0) - // { - // request(GRAPHQL!, - // `mutation handleTransfer( $from: String!, $to: String!, $value: Int!, $pairAddress: String!, $deployHash: String!, $timeStamp: String!, $blockHash: String!){ - // handleTransfer( from: $from, to: $to, value: $value, pairAddress: $pairAddress, deployHash: $deployHash, timeStamp: $timeStamp, blockHash: $blockHash) { - // result - // } - - // }`, - // {from:from, to: to, value: value, pairAddress: to, deployHash:deploy.deployHash,timeStamp:timestamp.toString(), blockHash:block_hash}) - // .then(data => console.log(data)) - // .catch(error => console.error(error)); - // } - - // } - // else if(eventName=="transfer") - // { - // console.log(eventName+ " Event result: "); - // console.log(newData[0][0].data + " = " + newData[0][1].data); - // console.log(newData[1][0].data + " = " + newData[1][1].data); - - // console.log(newData[2][0].data + " = " + newData[2][1].data); - // console.log(newData[3][0].data + " = " + newData[3][1].data); - // console.log(newData[4][0].data + " = " + newData[4][1].data); - // console.log(newData[5][0].data + " = " + newData[5][1].data); - - // var from=splitdata(newData[2][1].data); - // var to=splitdata(newData[4][1].data); - // var value=parseInt(newData[5][1].data); - // var pair=splitdata(newData[3][1].data); - - // console.log("from: ", from); - // console.log("to: ", to); - // console.log("value: ",value); - // console.log("pair: ", pair); - - // request(GRAPHQL!, - // `mutation handleTransfer( $from: String!, $to: String!, $value: Int!, $pairAddress: String!, $deployHash: String!, $timeStamp: String!, $blockHash: String!){ - // handleTransfer( from: $from, to: $to, value: $value, pairAddress: $pairAddress, deployHash: $deployHash, timeStamp: $timeStamp, blockHash: $blockHash) { - // result - // } - - // }`, - // {from:from, to: to, value: value, pairAddress: pair, deployHash:deploy.deployHash,timeStamp:timestamp.toString(), blockHash:block_hash}) - // .then(data => console.log(data)) - // .catch(error => console.error(error)); - // } - // else if (eventName=="mint") - // { - - // console.log(eventName+ " Event result: "); - // console.log(newData[0][0].data + " = " + newData[0][1].data); - // console.log(newData[1][0].data + " = " + newData[1][1].data); - // console.log(newData[2][0].data + " = " + newData[2][1].data); - // console.log(newData[3][0].data + " = " + newData[3][1].data); - // console.log(newData[4][0].data + " = " + newData[4][1].data); - // console.log(newData[5][0].data + " = " + newData[5][1].data); - - // var amount0=parseInt(newData[0][1].data); - // var amount1=parseInt(newData[1][1].data); - // var pair=splitdata(newData[4][1].data); - // var sender=splitdata(newData[5][1].data); - - // console.log("amount0: ", amount0); - // console.log("amount1: ", amount1); - // console.log("pair: ",pair); - // console.log("sender: ", sender); - - // request(GRAPHQL!, - // `mutation handleMint( $amount0: Int!, $amount1: Int!, $sender: String!,$logIndex: Int!, $pairAddress: String!, $deployHash: String!, $timeStamp: String!, $blockHash: String!){ - // handleMint( amount0: $amount0, amount1: $amount1, sender: $sender, logIndex: $logIndex, pairAddress: $pairAddress, deployHash: $deployHash, timeStamp: $timeStamp, blockHash: $blockHash) { - // result - // } - - // }`, - // {amount0:amount0, amount1: amount1, sender: sender,logIndex:0, pairAddress: pair, deployHash:deploy.deployHash,timeStamp:timestamp.toString(), blockHash:block_hash}) - // .then(data => console.log(data)) - // .catch(error => console.error(error)); - // } - // else if (eventName=="burn") - // { - - // console.log(eventName+ " Event result: "); - // console.log(newData[0][0].data + " = " + newData[0][1].data); - // console.log(newData[1][0].data + " = " + newData[1][1].data); - // console.log(newData[2][0].data + " = " + newData[2][1].data); - // console.log(newData[3][0].data + " = " + newData[3][1].data); - // console.log(newData[4][0].data + " = " + newData[4][1].data); - // console.log(newData[5][0].data + " = " + newData[5][1].data); - // console.log(newData[6][0].data + " = " + newData[6][1].data); - - // var amount0=parseInt(newData[0][1].data); - // var amount1=parseInt(newData[1][1].data); - // var pair=splitdata(newData[4][1].data); - // var sender=splitdata(newData[5][1].data); - // var to=splitdata(newData[6][1].data); - - // console.log("amount0: ", amount0); - // console.log("amount1: ", amount1); - // console.log("pair: ",pair); - // console.log("sender: ", sender); - // console.log("to: ", to); - - // request(GRAPHQL!, - // `mutation handleBurn( $amount0: Int!, $amount1: Int!, $sender: String!,$logIndex: Int!,$to: String!, $pairAddress: String!, $deployHash: String!, $timeStamp: String!, $blockHash: String!){ - // handleBurn( amount0: $amount0, amount1: $amount1, sender: $sender, logIndex: $logIndex, to:$to, pairAddress: $pairAddress, deployHash: $deployHash, timeStamp: $timeStamp, blockHash: $blockHash) { - // result - // } - - // }`, - // {amount0:amount0, amount1: amount1, sender: sender,logIndex:0, to:to,pairAddress: pair, deployHash:deploy.deployHash,timeStamp:timestamp.toString(), blockHash:block_hash}) - // .then(data => console.log(data)) - // .catch(error => console.error(error)); - // } - // else if (eventName=="sync") - // { - - // console.log(eventName+ " Event result: "); - // console.log(newData[0][0].data + " = " + newData[0][1].data); - // console.log(newData[1][0].data + " = " + newData[1][1].data); - // console.log(newData[2][0].data + " = " + newData[2][1].data); - // console.log(newData[3][0].data + " = " + newData[3][1].data); - // console.log(newData[4][0].data + " = " + newData[4][1].data); - - // var reserve0=parseInt(newData[3][1].data); - // var reserve1=parseInt(newData[4][1].data); - // var pair=splitdata(newData[2][1].data); - - // console.log("reserve0: ", reserve0); - // console.log("reserve1: ", reserve1); - // console.log("pair: ",pair); - - - // request(GRAPHQL!, - // `mutation handleSync( $reserve0: Int!, $reserve1: Int!, $pairAddress: String!){ - // handleSync( reserve0: $reserve0, reserve1: $reserve1, pairAddress: $pairAddress) { - // result - // } - - // }`, - // {reserve0:reserve0, reserve1: reserve1, pairAddress: pair}) - // .then(data => console.log(data)) - // .catch(error => console.error(error)); - // } - // else if (eventName=="swap") - // { - - // console.log(eventName+ " Event result: "); - // console.log(newData[0][0].data + " = " + newData[0][1].data); - // console.log(newData[1][0].data + " = " + newData[1][1].data); - // console.log(newData[2][0].data + " = " + newData[2][1].data); - // console.log(newData[3][0].data + " = " + newData[3][1].data); - // console.log(newData[4][0].data + " = " + newData[4][1].data); - // console.log(newData[5][0].data + " = " + newData[5][1].data); - // console.log(newData[6][0].data + " = " + newData[6][1].data); - // console.log(newData[7][0].data + " = " + newData[7][1].data); - // console.log(newData[8][0].data + " = " + newData[8][1].data); - // console.log(newData[9][0].data + " = " + newData[9][1].data); - - // var amount0In=parseInt(newData[0][1].data); - // var amount1In=parseInt(newData[1][1].data); - // var amount0Out=parseInt(newData[2][1].data); - // var amount1Out=parseInt(newData[3][1].data); - // var from=splitdata(newData[6][1].data); - // var pair=splitdata(newData[7][1].data); - // var sender=splitdata(newData[8][1].data); - // var to=splitdata(newData[9][1].data); - - // console.log("amount0In: ", amount0In); - // console.log("amount1In: ", amount1In); - // console.log("amount0Out: ", amount0Out); - // console.log("amount1Out: ", amount1Out); - // console.log("from: ",from); - // console.log("pair: ",pair); - // console.log("sender: ", sender); - // console.log("to: ", to); - - // request(GRAPHQL!, - // `mutation handleSwap( $amount0In: Int!, $amount1In: Int!, $amount0Out: Int!, $amount1Out: Int!, $to: String!,$from: String!,$sender: String!,$logIndex: Int!, $pairAddress: String!, $deployHash: String!, $timeStamp: String!, $blockHash: String!){ - // handleSwap( amount0In: $amount0In, amount1In: $amount1In, amount0Out: $amount0Out, amount1Out: $amount1Out, to:$to, from:$from,sender: $sender,logIndex: $logIndex, pairAddress: $pairAddress, deployHash: $deployHash, timeStamp: $timeStamp, blockHash: $blockHash) { - // result - // } - - // }`, - // {amount0In:amount0In, amount1In: amount1In,amount0Out:amount0Out, amount1Out: amount1Out,to:to,from:from, sender: sender,logIndex:0,pairAddress: pair, deployHash:deploy.deployHash,timeStamp:timestamp.toString(), blockHash:block_hash}) - // .then(data => console.log(data)) - // .catch(error => console.error(error)); - // } - - - // } else { - // console.log(`Failed deploy of ${eventName}, deployHash: ${deploy.deployHash}`); - // console.log(`Error: ${deploy.error}`); - // } - // } - // ); - await sleep(5 * 1000); let accountInfo = await utils.getAccountInfo(NODE_ADDRESS!, KEYS.publicKey); diff --git a/JsClients/ROUTER/src/uniswap-router-client.ts b/JsClients/ROUTER/src/uniswap-router-client.ts index 092b9027..67de6d28 100644 --- a/JsClients/ROUTER/src/uniswap-router-client.ts +++ b/JsClients/ROUTER/src/uniswap-router-client.ts @@ -177,15 +177,6 @@ class UniswapRouterClient { }); if (deployHash !== null) { - this.addPendingDeploy(RouterEvents.PairCreated, deployHash); - this.addPendingDeploy(RouterEvents.Erc20Transfer, deployHash); - this.addPendingDeploy(RouterEvents.Approval, deployHash); - this.addPendingDeploy(RouterEvents.Erc20Transfer, deployHash); - this.addPendingDeploy(RouterEvents.Approval, deployHash); - this.addPendingDeploy(RouterEvents.Transfer, deployHash); - this.addPendingDeploy(RouterEvents.Transfer, deployHash); - this.addPendingDeploy(RouterEvents.Sync, deployHash); - this.addPendingDeploy(RouterEvents.Mint, deployHash); return deployHash; } else { throw Error("Invalid Deploy"); @@ -227,10 +218,7 @@ class UniswapRouterClient { }); if (deployHash !== null) { - this.addPendingDeploy(RouterEvents.PairCreated, deployHash); - this.addPendingDeploy(RouterEvents.Transfer, deployHash); - this.addPendingDeploy(RouterEvents.Sync, deployHash); - this.addPendingDeploy(RouterEvents.Mint, deployHash); + return deployHash; } else { throw Error("Invalid Deploy"); @@ -277,9 +265,7 @@ class UniswapRouterClient { }); if (deployHash !== null) { - this.addPendingDeploy(RouterEvents.Transfer, deployHash); - this.addPendingDeploy(RouterEvents.Sync, deployHash); - this.addPendingDeploy(RouterEvents.Burn, deployHash); + return deployHash; } else { throw Error("Invalid Deploy"); @@ -319,9 +305,7 @@ class UniswapRouterClient { }); if (deployHash !== null) { - this.addPendingDeploy(RouterEvents.Transfer, deployHash); - this.addPendingDeploy(RouterEvents.Sync, deployHash); - this.addPendingDeploy(RouterEvents.Burn, deployHash); + return deployHash; } else { throw Error("Invalid Deploy"); @@ -377,10 +361,7 @@ class UniswapRouterClient { }); if (deployHash !== null) { - this.addPendingDeploy(RouterEvents.Approval, deployHash); - this.addPendingDeploy(RouterEvents.Transfer, deployHash); - this.addPendingDeploy(RouterEvents.Sync, deployHash); - this.addPendingDeploy(RouterEvents.Burn, deployHash); + return deployHash; } else { throw Error("Invalid Deploy"); @@ -428,10 +409,7 @@ class UniswapRouterClient { }); if (deployHash !== null) { - this.addPendingDeploy(RouterEvents.Approval, deployHash); - this.addPendingDeploy(RouterEvents.Transfer, deployHash); - this.addPendingDeploy(RouterEvents.Sync, deployHash); - this.addPendingDeploy(RouterEvents.Burn, deployHash); + return deployHash; } else { throw Error("Invalid Deploy"); @@ -481,9 +459,6 @@ class UniswapRouterClient { if (deployHash !== null) { - this.addPendingDeploy(RouterEvents.Transfer, deployHash); - this.addPendingDeploy(RouterEvents.Sync, deployHash); - this.addPendingDeploy(RouterEvents.Swap, deployHash); return deployHash; } else { throw Error("Invalid Deploy"); @@ -526,9 +501,7 @@ class UniswapRouterClient { }); if (deployHash !== null) { - this.addPendingDeploy(RouterEvents.Transfer, deployHash); - this.addPendingDeploy(RouterEvents.Sync, deployHash); - this.addPendingDeploy(RouterEvents.Swap, deployHash); + return deployHash; } else { throw Error("Invalid Deploy"); @@ -570,9 +543,7 @@ class UniswapRouterClient { }); if (deployHash !== null) { - this.addPendingDeploy(RouterEvents.Transfer, deployHash); - this.addPendingDeploy(RouterEvents.Sync, deployHash); - this.addPendingDeploy(RouterEvents.Swap, deployHash); + return deployHash; } else { throw Error("Invalid Deploy"); @@ -614,9 +585,7 @@ class UniswapRouterClient { }); if (deployHash !== null) { - this.addPendingDeploy(RouterEvents.Transfer, deployHash); - this.addPendingDeploy(RouterEvents.Sync, deployHash); - this.addPendingDeploy(RouterEvents.Swap, deployHash); + return deployHash; } else { throw Error("Invalid Deploy"); @@ -658,9 +627,7 @@ class UniswapRouterClient { }); if (deployHash !== null) { - this.addPendingDeploy(RouterEvents.Transfer, deployHash); - this.addPendingDeploy(RouterEvents.Sync, deployHash); - this.addPendingDeploy(RouterEvents.Swap, deployHash); + return deployHash; } else { throw Error("Invalid Deploy"); @@ -710,9 +677,7 @@ class UniswapRouterClient { }); if (deployHash !== null) { - this.addPendingDeploy(RouterEvents.Transfer, deployHash); - this.addPendingDeploy(RouterEvents.Sync, deployHash); - this.addPendingDeploy(RouterEvents.Swap, deployHash); + return deployHash; } else { throw Error("Invalid Deploy"); diff --git a/JsClients/WCSPR/keys/public_key.pem b/JsClients/WCSPR/keys/public_key.pem deleted file mode 100644 index 6a348344..00000000 --- a/JsClients/WCSPR/keys/public_key.pem +++ /dev/null @@ -1,3 +0,0 @@ ------BEGIN PUBLIC KEY----- -MCowBQYDK2VwAyEAkiDYds03hKjSdfJng8iSp3bx4V/aEbDAYJt6Ny+cz9Q= ------END PUBLIC KEY----- diff --git a/JsClients/WCSPR/keys/public_key_hex b/JsClients/WCSPR/keys/public_key_hex deleted file mode 100644 index b69ed86d..00000000 --- a/JsClients/WCSPR/keys/public_key_hex +++ /dev/null @@ -1 +0,0 @@ -019220d876cd3784a8d275f26783c892a776f1e15fda11b0c0609b7a372f9ccfd4 \ No newline at end of file diff --git a/JsClients/WCSPR/keys/secret_key.pem b/JsClients/WCSPR/keys/secret_key.pem deleted file mode 100644 index c7e58e13..00000000 --- a/JsClients/WCSPR/keys/secret_key.pem +++ /dev/null @@ -1,3 +0,0 @@ ------BEGIN PRIVATE KEY----- -MC4CAQAwBQYDK2VwBCIEINn5R/VQW1MUs0NC5XmmN7SBAgZIx9v4ModUIPb6Pc64 ------END PRIVATE KEY----- diff --git a/JsClients/WCSPR/src/constants.ts b/JsClients/WCSPR/src/constants.ts deleted file mode 100644 index 7817c7d2..00000000 --- a/JsClients/WCSPR/src/constants.ts +++ /dev/null @@ -1,5 +0,0 @@ -export enum ERC20Events { - Approval="approve", - Transfer="erc20_transfer" -} - diff --git a/JsClients/WCSPR/src/erc20.ts b/JsClients/WCSPR/src/erc20.ts deleted file mode 100644 index 425c0e66..00000000 --- a/JsClients/WCSPR/src/erc20.ts +++ /dev/null @@ -1,664 +0,0 @@ -import { - CasperClient, - CLPublicKey, - CLAccountHash, - CLByteArray, - CLKey, - CLString, - CLTypeBuilder, - CLValue, - CLValueBuilder, - CLValueParsers, - CLMap, - DeployUtil, - EventName, - EventStream, - Keys, - RuntimeArgs, -} from "casper-js-sdk"; -import { Some, None } from "ts-results"; -import { ERC20Events } from "./constants"; -import * as utils from "./utils"; -import { RecipientType, IPendingDeploy } from "./types"; - -class ERC20Client { - private contractName: string = "erc20"; - private contractHash: string= "erc20"; - private contractPackageHash: string= "erc20"; - private namedKeys: { - balances:string - metadata: string; - nonces: string; - allowances: string; - ownedTokens: string; - owners: string; - paused: string; - - }; - - private isListening = false; - private pendingDeploys: IPendingDeploy[] = []; - - constructor( - - private nodeAddress: string, - private chainName: string, - private eventStreamAddress?: string, - - ) - { - this.namedKeys= { - balances:"null", - metadata: "null", - nonces: "null", - allowances: "null", - ownedTokens: "null", - owners: "null", - paused: "null" - }; - } - - public async install( - keys: Keys.AsymmetricKey, - tokenName: string, - tokenSymbol: string, - decimals: string, - totalSupply: string, - contractName: string, - paymentAmount: string, - wasmPath: string - ) { - const runtimeArgs = RuntimeArgs.fromMap({ - name: CLValueBuilder.string(tokenName), - symbol: CLValueBuilder.string(tokenSymbol), - decimals: CLValueBuilder.u8(decimals), - initial_supply: CLValueBuilder.u256(totalSupply), - contract_name: CLValueBuilder.string(contractName), - }); - - const deployHash = await installWasmFile({ - chainName: this.chainName, - paymentAmount, - nodeAddress: this.nodeAddress, - keys, - pathToContract: wasmPath, - runtimeArgs, - }); - - if (deployHash !== null) { - return deployHash; - } else { - throw Error("Problem with installation"); - } - } - - public async setContractHash(hash: string) { - const stateRootHash = await utils.getStateRootHash(this.nodeAddress); - const contractData = await utils.getContractData( - this.nodeAddress, - stateRootHash, - hash - ); - - const { contractPackageHash, namedKeys } = contractData.Contract!; - this.contractHash = hash; - this.contractPackageHash = contractPackageHash.replace( - "contract-package-wasm", - "" - ); - const LIST_OF_NAMED_KEYS = [ - 'balances', - 'nonces', - 'allowances', - `${this.contractName}_package_hash`, - `${this.contractName}_package_hash_wrapped`, - `${this.contractName}_contract_hash`, - `${this.contractName}_contract_hash_wrapped`, - `${this.contractName}_package_access_token`, - ]; - // @ts-ignore - this.namedKeys = namedKeys.reduce((acc, val) => { - if (LIST_OF_NAMED_KEYS.includes(val.name)) { - return { ...acc, [utils.camelCased(val.name)]: val.key }; - } - return acc; - }, {}); - } - - public async name() { - const result = await contractSimpleGetter( - this.nodeAddress, - this.contractHash, - ["name"] - ); - return result.value(); - } - - public async symbol() { - const result = await contractSimpleGetter( - this.nodeAddress, - this.contractHash, - ["symbol"] - ); - return result.value(); - } - - public async decimal() { - const result = await contractSimpleGetter( - this.nodeAddress, - this.contractHash, - ["decimals"] - ); - return result.value(); - } - public async balanceOf(account: CLPublicKey) { - - const accountHash = Buffer.from(account.toAccountHash()).toString("hex"); - const result = await utils.contractDictionaryGetter( - this.nodeAddress, - accountHash, - this.namedKeys.balances - ); - const maybeValue = result.value().unwrap(); - return maybeValue.value().toString(); - } - public async balanceOfcontract(accountHash: string) { - - //const accountHash = Buffer.from(account.toAccountHash()).toString("hex"); - const result = await utils.contractDictionaryGetter( - this.nodeAddress, - accountHash, - this.namedKeys.balances - ); - const maybeValue = result.value().unwrap(); - return maybeValue.value().toString(); - } - - public async nonce(account: CLPublicKey) { - const accountHash = Buffer.from(account.toAccountHash()).toString("hex"); - const result = await utils.contractDictionaryGetter( - this.nodeAddress, - accountHash, - this.namedKeys.nonces - ); - const maybeValue = result.value().unwrap(); - return maybeValue.value().toString(); - } - - public async allowance(owner: CLPublicKey, spender: CLPublicKey) { - const ownerAccountHash = Buffer.from(owner.toAccountHash()).toString("hex"); - const spenderAccountHash = Buffer.from(spender.toAccountHash()).toString("hex"); - const accountHash: string = `${ownerAccountHash}_${spenderAccountHash}`; - const result = await utils.contractDictionaryGetter( - this.nodeAddress, - accountHash, - this.namedKeys.allowances - ); - const maybeValue = result.value().unwrap(); - return maybeValue.value().toString(); - } - - public async totalSupply() { - const result = await contractSimpleGetter( - this.nodeAddress, - this.contractHash, - ["total_supply"] - ); - return result.value(); - } - - public async approve( - keys: Keys.AsymmetricKey, - spender: string, - amount: string, - paymentAmount: string - ) { - - const _spender = new CLByteArray( - Uint8Array.from(Buffer.from(spender, "hex")) - ); - const runtimeArgs = RuntimeArgs.fromMap({ - spender: utils.createRecipientAddress(_spender), - amount: CLValueBuilder.u256(amount) - }); - - - const deployHash = await contractCall({ - chainName: this.chainName, - contractHash: this.contractHash, - entryPoint: "approve", - keys, - nodeAddress: this.nodeAddress, - paymentAmount, - runtimeArgs, - }); - - if (deployHash !== null) { - this.addPendingDeploy(ERC20Events.Approval, deployHash); - return deployHash; - } else { - throw Error("Invalid Deploy"); - } - } - public async transfer( - keys: Keys.AsymmetricKey, - recipient: RecipientType, - amount: string, - paymentAmount: string - ) { - - const runtimeArgs = RuntimeArgs.fromMap({ - recipient: utils.createRecipientAddress(recipient), - amount: CLValueBuilder.u256(amount) - }); - - - const deployHash = await contractCall({ - chainName: this.chainName, - contractHash: this.contractHash, - entryPoint: "transfer", - keys, - nodeAddress: this.nodeAddress, - paymentAmount, - runtimeArgs, - }); - - if (deployHash !== null) { - this.addPendingDeploy(ERC20Events.Transfer, deployHash); - return deployHash; - } else { - throw Error("Invalid Deploy"); - } - } - public async transferFrom( - keys: Keys.AsymmetricKey, - owner: RecipientType, - recipient: RecipientType, - amount: string, - paymentAmount: string - ) { - - const runtimeArgs = RuntimeArgs.fromMap({ - owner: utils.createRecipientAddress(owner), - recipient: utils.createRecipientAddress(recipient), - amount: CLValueBuilder.u256(amount) - }); - - - const deployHash = await contractCall({ - chainName: this.chainName, - contractHash: this.contractHash, - entryPoint: "transfer_from", - keys, - nodeAddress: this.nodeAddress, - paymentAmount, - runtimeArgs, - }); - - if (deployHash !== null) { - this.addPendingDeploy(ERC20Events.Transfer, deployHash); - return deployHash; - } else { - throw Error("Invalid Deploy"); - } - } - public async deposit_no_return( - keys: Keys.AsymmetricKey, - purse: RecipientType, - amount: string, - paymentAmount: string - ) { - - const runtimeArgs = RuntimeArgs.fromMap({ - purse:utils.createRecipientAddress(purse), - amount: CLValueBuilder.u256(amount) - }); - - const deployHash = await contractCall({ - chainName: this.chainName, - contractHash: this.contractHash, - entryPoint: "deposit_no_return", - keys, - nodeAddress: this.nodeAddress, - paymentAmount, - runtimeArgs, - }); - - if (deployHash !== null) { - //this.addPendingDeploy(ERC20Events.Transfer, deployHash); - return deployHash; - } else { - throw Error("Invalid Deploy"); - } - } - // public async mint( - // keys: Keys.AsymmetricKey, - // to: string, - // amount: string, - // paymentAmount: string - // ) { - // const tobytearray = new CLByteArray(Uint8Array.from(Buffer.from(to, 'hex'))); - // const runtimeArgs = RuntimeArgs.fromMap({ - // to: CLValueBuilder.key(tobytearray), - // amount: CLValueBuilder.u256(amount) - // }); - - - // const deployHash = await contractCall({ - // chainName: this.chainName, - // contractHash: this.contractHash, - // entryPoint: "mint", - // keys, - // nodeAddress: this.nodeAddress, - // paymentAmount, - // runtimeArgs, - // }); - - // if (deployHash !== null) { - // this.addPendingDeploy(ERC20Events.Transfer, deployHash); - // return deployHash; - // } else { - // throw Error("Invalid Deploy"); - // } - // } - public async burn( - keys: Keys.AsymmetricKey, - from: RecipientType, - amount: string, - paymentAmount: string - ) { - - const runtimeArgs = RuntimeArgs.fromMap({ - from: utils.createRecipientAddress(from), - amount: CLValueBuilder.u256(amount) - }); - - - const deployHash = await contractCall({ - chainName: this.chainName, - contractHash: this.contractHash, - entryPoint: "burn", - keys, - nodeAddress: this.nodeAddress, - paymentAmount, - runtimeArgs, - }); - - if (deployHash !== null) { - this.addPendingDeploy(ERC20Events.Transfer, deployHash); - return deployHash; - } else { - throw Error("Invalid Deploy"); - } - } - public async permit( - keys: Keys.AsymmetricKey, - publicKey: string, - signature: string, - owner: RecipientType, - spender: RecipientType, - amount: string, - deadline: string, - paymentAmount: string - ) { - - const runtimeArgs = RuntimeArgs.fromMap({ - public: CLValueBuilder.string(publicKey), - signature: CLValueBuilder.string(signature), - owner: utils.createRecipientAddress(owner), - spender: utils.createRecipientAddress(spender), - value: CLValueBuilder.u256(amount), - deadline: CLValueBuilder.u64(deadline) - }); - - - const deployHash = await contractCall({ - chainName: this.chainName, - contractHash: this.contractHash, - entryPoint: "permit", - keys, - nodeAddress: this.nodeAddress, - paymentAmount, - runtimeArgs, - }); - - if (deployHash !== null) { - this.addPendingDeploy(ERC20Events.Approval, deployHash); - return deployHash; - } else { - throw Error("Invalid Deploy"); - } - } - - 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 { - nodeAddress: string; - keys: Keys.AsymmetricKey; - chainName: string; - pathToContract: string; - runtimeArgs: RuntimeArgs; - paymentAmount: string; -} - -const installWasmFile = async ({ - nodeAddress, - keys, - chainName, - pathToContract, - runtimeArgs, - paymentAmount, -}: IInstallParams): Promise => { - const client = new CasperClient(nodeAddress); - - // Set contract installation deploy (unsigned). - let deploy = DeployUtil.makeDeploy( - new DeployUtil.DeployParams( - CLPublicKey.fromHex(keys.publicKey.toHex()), - chainName - ), - DeployUtil.ExecutableDeployItem.newModuleBytes( - utils.getBinary(pathToContract), - runtimeArgs - ), - DeployUtil.standardPayment(paymentAmount) - ); - - // Sign deploy. - deploy = client.signDeploy(deploy, keys); - - // Dispatch deploy to node. - return await client.putDeploy(deploy); -}; - -interface IContractCallParams { - nodeAddress: string; - keys: Keys.AsymmetricKey; - chainName: string; - entryPoint: string; - runtimeArgs: RuntimeArgs; - paymentAmount: string; - contractHash: string; -} - -const contractCall = async ({ - nodeAddress, - keys, - chainName, - contractHash, - entryPoint, - runtimeArgs, - paymentAmount, -}: IContractCallParams) => { - const client = new CasperClient(nodeAddress); - const contractHashAsByteArray = utils.contractHashToByteArray(contractHash); - - let deploy = DeployUtil.makeDeploy( - new DeployUtil.DeployParams(keys.publicKey, chainName), - DeployUtil.ExecutableDeployItem.newStoredContractByHash( - contractHashAsByteArray, - entryPoint, - runtimeArgs - ), - DeployUtil.standardPayment(paymentAmount) - ); - - // Sign deploy. - deploy = client.signDeploy(deploy, keys); - - // Dispatch deploy to node. - const deployHash = await client.putDeploy(deploy); - - return deployHash; -}; - -const contractSimpleGetter = async ( - nodeAddress: string, - contractHash: string, - key: string[] -) => { - const stateRootHash = await utils.getStateRootHash(nodeAddress); - const clValue = await utils.getContractData( - nodeAddress, - stateRootHash, - contractHash, - key - ); - - if (clValue && clValue.CLValue instanceof CLValue) { - return clValue.CLValue!; - } else { - throw Error("Invalid stored value"); - } -}; - -const toCLMap = (map: Map) => { - const clMap = CLValueBuilder.map([ - CLTypeBuilder.string(), - CLTypeBuilder.string(), - ]); - for (const [key, value] of Array.from(map.entries())) { - clMap.set(CLValueBuilder.string(key), CLValueBuilder.string(value)); - } - return clMap; -}; - -const fromCLMap = (map: Map) => { - const jsMap = new Map(); - for (const [key, value] of Array.from(map.entries())) { - jsMap.set(key.value(), value.value()); - } - return jsMap; -}; - -export default ERC20Client; diff --git a/JsClients/WCSPR/src/index.ts b/JsClients/WCSPR/src/index.ts deleted file mode 100644 index 2c10e006..00000000 --- a/JsClients/WCSPR/src/index.ts +++ /dev/null @@ -1,9 +0,0 @@ -import ERC20Client from "./erc20"; -import * as utils from "./utils"; -import * as constants from "./constants"; - -export { - ERC20Client, - utils, - constants -}; diff --git a/JsClients/WCSPR/src/types.d.ts b/JsClients/WCSPR/src/types.d.ts deleted file mode 100644 index af90b09b..00000000 --- a/JsClients/WCSPR/src/types.d.ts +++ /dev/null @@ -1,9 +0,0 @@ -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/WCSPR/src/utils.ts b/JsClients/WCSPR/src/utils.ts deleted file mode 100644 index 909a7d64..00000000 --- a/JsClients/WCSPR/src/utils.ts +++ /dev/null @@ -1,125 +0,0 @@ -import { - CasperServiceByJsonRPC, - CLValue, - CLKey, - CLAccountHash, - Keys, - CLPublicKey, -} from "casper-js-sdk"; -import fs from "fs"; - -import { RecipientType } from "./types"; - -export const camelCased = (myString: string) => - myString.replace(/_([a-z])/g, (g) => g[1].toUpperCase()); - -export const createRecipientAddress = (recipient: RecipientType): CLKey => { - if (recipient instanceof CLPublicKey) { - return new CLKey(new CLAccountHash(recipient.toAccountHash())); - } else { - return new CLKey(recipient); - } -}; - -/** - * Returns an ECC key pair mapped to an NCTL faucet account. - * @param pathToFaucet - Path to NCTL faucet directory. - */ -export const getKeyPairOfContract = (pathToFaucet: string) => - Keys.Ed25519.parseKeyFiles( - `${pathToFaucet}/public_key.pem`, - `${pathToFaucet}/secret_key.pem` - ); - -/** - * Returns a binary as u8 array. - * @param pathToBinary - Path to binary file to be loaded into memory. - * @return Uint8Array Byte array. - */ -export const getBinary = (pathToBinary: string) => { - return new Uint8Array(fs.readFileSync(pathToBinary, null).buffer); -}; - -/** - * Returns global state root hash at current block. - * @param {Object} client - JS SDK client for interacting with a node. - * @return {String} Root hash of global state at most recent block. - */ -export const getStateRootHash = async (nodeAddress: string) => { - const client = new CasperServiceByJsonRPC(nodeAddress); - const { block } = await client.getLatestBlockInfo(); - if (block) { - return block.header.state_root_hash; - } else { - throw Error("Problem when calling getLatestBlockInfo"); - } -}; - -export const getAccountInfo = async ( - nodeAddress: string, - publicKey: CLPublicKey -) => { - const stateRootHash = await getStateRootHash(nodeAddress); - const client = new CasperServiceByJsonRPC(nodeAddress); - const accountHash = publicKey.toAccountHashStr(); - const blockState = await client.getBlockState(stateRootHash, accountHash, []); - return blockState.Account; -}; - -/** - * Returns a value under an on-chain account's storage. - * @param accountInfo - On-chain account's info. - * @param namedKey - A named key associated with an on-chain account. - */ -export const getAccountNamedKeyValue = (accountInfo: any, namedKey: string) => { - const found = accountInfo.namedKeys.find((i: any) => i.name === namedKey); - if (found) { - return found.key; - } - return undefined; -}; - -export const getContractData = async ( - nodeAddress: string, - stateRootHash: string, - contractHash: string, - path: string[] = [] -) => { - const client = new CasperServiceByJsonRPC(nodeAddress); - const blockState = await client.getBlockState( - stateRootHash, - `hash-${contractHash}`, - path - ); - return blockState; -}; - -export const contractDictionaryGetter = async ( - nodeAddress: string, - dictionaryItemKey: string, - seedUref: string, -) => { - const stateRootHash = await getStateRootHash(nodeAddress); - - const client = new CasperServiceByJsonRPC(nodeAddress); - - const storedValue = await client.getDictionaryItemByURef( - stateRootHash, - dictionaryItemKey, - seedUref - ); - - if (storedValue && storedValue.CLValue instanceof CLValue) { - return storedValue.CLValue!; - } else { - throw Error("Invalid stored value"); - } -}; - - -export const contractHashToByteArray = (contractHash: string) => - Uint8Array.from(Buffer.from(contractHash, "hex")); - -export const sleep = (num: number) => { - return new Promise((resolve) => setTimeout(resolve, num)); -}; diff --git a/JsClients/WCSPR/test/install.ts b/JsClients/WCSPR/test/install.ts deleted file mode 100644 index b1dd1453..00000000 --- a/JsClients/WCSPR/test/install.ts +++ /dev/null @@ -1,73 +0,0 @@ -import { config } from "dotenv"; -config(); -import { ERC20Client, utils, constants } from "../src"; -import { parseTokenMeta, sleep, getDeploy } from "./utils"; - -import { - Keys, -} from "casper-js-sdk"; - -const { - NODE_ADDRESS, - EVENT_STREAM_ADDRESS, - CHAIN_NAME, - ERC20_WASM_PATH, - ERC20_MASTER_KEY_PAIR_PATH, - ERC20_INSTALL_PAYMENT_AMOUNT, - ERC20_CONTRACT_NAME, - ERC20_TOKEN_NAME, - ERC20_TOKEN_SYMBOL, - ERC20_DECIMALS, - ERC20_TOTAL_SUPPLY -} = process.env; - -const KEYS = Keys.Ed25519.parseKeyFiles( - `${ERC20_MASTER_KEY_PAIR_PATH}/public_key.pem`, - `${ERC20_MASTER_KEY_PAIR_PATH}/secret_key.pem` -); - -const test = async () => { - const erc20 = new ERC20Client( - NODE_ADDRESS!, - CHAIN_NAME!, - EVENT_STREAM_ADDRESS! - ); - - const installDeployHash = await erc20.install( - KEYS, - ERC20_TOKEN_NAME!, - ERC20_TOKEN_SYMBOL!, - ERC20_DECIMALS!, - ERC20_TOTAL_SUPPLY!, - ERC20_CONTRACT_NAME!, - ERC20_INSTALL_PAYMENT_AMOUNT!, - ERC20_WASM_PATH! - ); - - console.log(`... Contract installation deployHash: ${installDeployHash}`); - - await getDeploy(NODE_ADDRESS!, installDeployHash); - - 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)); - - const contractHash = await utils.getAccountNamedKeyValue( - accountInfo, - `${ERC20_CONTRACT_NAME!}_contract_hash` - ); - - console.log(`... Contract Hash: ${contractHash}`); - - const packageHash = await utils.getAccountNamedKeyValue( - accountInfo, - `${ERC20_CONTRACT_NAME!}_package_hash` - ); - - console.log(`... Package Hash: ${packageHash}`); -}; - -//test(); diff --git a/JsClients/WCSPR/test/installed.ts b/JsClients/WCSPR/test/installed.ts deleted file mode 100644 index 6a3e1745..00000000 --- a/JsClients/WCSPR/test/installed.ts +++ /dev/null @@ -1,302 +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, -} 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, - WCSPR -} = process.env; - - -const KEYS = Keys.Ed25519.parseKeyFiles( - `${MASTER_KEY_PAIR_PATH}/public_key.pem`, - `${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 () => { - - // const listener = erc20.onEvent( - // [ - // ERC20Events.Approval, - // ERC20Events.Transfer - // ], - // async (eventName, deploy, result) => { - // if (deploy.success) { - // console.log(`Successfull deploy of: ${eventName}, deployHash: ${deploy.deployHash}`); - // const [timestamp,gasPrice,block_hash]= await getDeploy(NODE_ADDRESS!, deploy.deployHash); - // console.log("... Deployhash: ", deploy.deployHash); - // console.log("... Timestamp: ", timestamp); - // //console.log("... GasPrice: ", gasPrice); - // console.log("... Block hash: ", block_hash); - - // let newData = JSON.parse(JSON.stringify(result.value())); - - // if(eventName=="approve") - // { - // console.log(eventName+ " Event result: "); - // console.log(newData[0][0].data + " = " + newData[0][1].data); - // console.log(newData[1][0].data + " = " + newData[1][1].data); - // console.log(newData[2][0].data + " = " + newData[2][1].data); - // console.log(newData[3][0].data + " = " + newData[3][1].data); - // console.log(newData[4][0].data + " = " + newData[4][1].data); - // } - // else if(eventName=="erc20_transfer") - // { - // console.log(eventName+ " Event result: "); - // console.log(newData[0][0].data + " = " + newData[0][1].data); - // console.log(newData[1][0].data + " = " + newData[1][1].data); - - // console.log(newData[2][0].data + " = " + newData[2][1].data); - // console.log(newData[3][0].data + " = " + newData[3][1].data); - // console.log(newData[4][0].data + " = " + newData[4][1].data); - - // var flag=0; - // var temp=(newData[3][1].data).split('('); - // console.log("temp[0]: ",temp[0]); - // if(temp[0] == "Key::Account(") - // { - // flag=1; - // } - // var from=splitdata(newData[2][1].data); - // var to=splitdata(newData[3][1].data); - // var value=parseInt(newData[4][1].data); - - // console.log("from: ", from); - // console.log("to: ", to); - // console.log("value: ",value); - - // if(flag==0) - // { - // request(GRAPHQL!, - // `mutation handleTransfer( $from: String!, $to: String!, $value: Int!, $pairAddress: String!, $deployHash: String!, $timeStamp: String!, $blockHash: String!){ - // handleTransfer( from: $from, to: $to, value: $value, pairAddress: $pairAddress, deployHash: $deployHash, timeStamp: $timeStamp, blockHash: $blockHash) { - // result - // } - - // }`, - // {from:from, to: to, value: value, pairAddress: to, deployHash:deploy.deployHash,timeStamp:timestamp.toString(), blockHash:block_hash}) - // .then(data => console.log(data)) - // .catch(error => console.error(error)); - // } - - // } - - // } else { - // console.log(`Failed deploy of ${eventName}, deployHash: ${deploy.deployHash}`); - // console.log(`Error: ${deploy.error}`); - // } - // } - // ); - // console.log("listener: ",listener); - - await erc20.setContractHash(WCSPR!); - - // // //name - // // const name = await erc20.name(); - // // console.log(`... Contract name: ${name}`); - - // // //symbol - // // const symbol = await erc20.symbol(); - // // console.log(`... Contract symbol: ${symbol}`); - - // // //decimal - // // const decimal = await erc20.decimal(); - // // console.log(`... Contract decimal: ${decimal}`); - - // // //totalsupply - // // let totalSupply = await erc20.totalSupply(); - // // console.log(`... Total supply: ${totalSupply}`); - - // // // //balanceof - // // let balance = await erc20.balanceOf(KEYS.publicKey); - // // console.log(`... Balance of account ${KEYS.publicKey.toAccountHashStr()}`); - // // console.log(`... Balance: ${balance}`); - - // // //nonce - // // let nonce = await erc20.nonce(KEYS.publicKey); - // // console.log(`... Nonce: ${nonce}`); - - // // // //allowance - // // // let allowance = await erc20.allowance(KEYS.publicKey,KEYS.publicKey); - // // // console.log(`... Allowance: ${allowance}`); - - //mint - const depositDeployHash = await erc20.deposit_no_return( - ROUTERKEYS, - ROUTERKEYS.publicKey, - MINT_AMOUNT!, - MINT_PAYMENT_AMOUNT! - ); - console.log("... Deposit deploy hash: ", depositDeployHash); - - await getDeploy(NODE_ADDRESS!, depositDeployHash); - console.log("... Deposited 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_A_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; - -}; diff --git a/JsClients/WCSPR/test/utils.ts b/JsClients/WCSPR/test/utils.ts deleted file mode 100644 index 54870037..00000000 --- a/JsClients/WCSPR/test/utils.ts +++ /dev/null @@ -1,34 +0,0 @@ -import { CasperClient } from "casper-js-sdk"; - -export const parseTokenMeta = (str: string): Array<[string, string]> => str.split(",").map(s => { - const map = s.split(" "); - return [map[0], map[1]] -}); - -export const sleep = (ms: number) => { - return new Promise(resolve => setTimeout(resolve, ms)); -} - -export const getDeploy = async (NODE_URL: string, deployHash: string) => { - const client = new CasperClient(NODE_URL); - let i = 300; - while (i != 0) { - //console.log("i: ",i); - const [deploy, raw] = await client.getDeploy(deployHash); - if (raw.execution_results.length !== 0){ - // @ts-ignore - if (raw.execution_results[0].result.Success) { - - return [deploy.header.timestamp,raw.execution_results[0].block_hash]; - } else { - // @ts-ignore - throw Error("Contract execution: " + raw.execution_results[0].result.Failure.error_message); - } - } else { - i--; - await sleep(1000); - continue; - } - } - throw Error('Timeout after ' + i + 's. Something\'s wrong'); -}