diff --git a/.env b/.env index ede56aeb..088b927f 100644 --- a/.env +++ b/.env @@ -2,15 +2,37 @@ NODE_MODE=deployed DATABASE_URL_LOCAL=mongodb://localhost:27017/V2-graphQL DATABASE_URL_ONLINE=mongodb+srv://admin:scytalelabs@cluster0-9yop5.mongodb.net/V2-graphQL-backend-demo?retryWrites=true&w=majority -FACTORY_CONTRACT=e135359661bd6F4D0A2f827e0e25F0B1E32bb44b538676c3aECBe543F93fc54F -FACTORY_CONTRACT_PACKAGE=9e00eE28318CDD9Ea3fc83eEad5EbEE916A798565d930b14638f196E725d537a -PAIR_CONTRACT=5B4C9719f6dac2F551bF0100Ff85B1469A1Ffd0F3b03Fd44125845404dF892a9 -PAIR_CONTRACT_PACKAGE=9b0C92894Bb7E9C0E657B2ba505C69263e435082Ac37dF982827061B86966B24 +FACTORY_CONTRACT=202dffe0821C291870c864378c38fCE0BC4Fe7EA571341c62243e92608005BEe +FACTORY_CONTRACT_PACKAGE=6fb092b2Da2Dc4C7Eb238E3770933A6C1Cd8B6bEcf7c0F7ABc89ecCB91682ffF +PAIR_CONTRACT=93855DECcfcD71b5d181ECf71e1987E353EE8eF75C25ED226172a2770d38d328 +PAIR_CONTRACT_PACKAGE=1D1b6671a573dFa566F75231eb058031DEf09C5c34E4Ac82C34a35fAf42cC6bf CALLEE_CONTRACT=fbfeda8b97f056f526f20c2fc2b486d9bdbfb3e46b9a164527e57c0c86e68612 -TOKEN0_CONTRACT=20831b61f3052df217EF0e441F4D7f365757Ae81Cb4C932408621cb7bf20b1c2 -TOKEN0_CONTRACT_PACKAGE=4DBe7c61F20d8FF91d8de2A70919235e2DF92d8C6212ffDc06989Ae59dA19059 -TOKEN1_CONTRACT=ba446757a580880faCa3B9FB52a014AB3d61C88C8B175609c44e362749D871E8 -TOKEN1_CONTRACT_PACKAGE=ec9518af5E73C169B20979cf44Dd582E69FD0b9044Fb60B041c438c56e778Ff1 +TOKEN0_CONTRACT=a29715B3d683D5D36F46AfaD71b8f7eaAb7B3c7aE554A86a09c6B101fa7264A0 +TOKEN0_CONTRACT_PACKAGE=B9F554b50D64bed3AbBD50dc11D368B5682ceC62faC5b235b190b05d4be16158 +TOKEN1_CONTRACT=2C2DeECA03Aa772E44189F6529dcad4380C5617D9F1f3C662a48cfc10Da2588A +TOKEN1_CONTRACT_PACKAGE=d59E12EEdeC37CCC70b3b58d85828B020b8311AE8D423Ab0f7da02b1fEd55B8A + +WETH_CONTRACT=2C2DeECA03Aa772E44189F6529dcad4380C5617D9F1f3C662a48cfc10Da2588A +WETH_CONTRACT_PACKAGE=d59E12EEdeC37CCC70b3b58d85828B020b8311AE8D423Ab0f7da02b1fEd55B8A + +DAI_CONTRACT=a29715B3d683D5D36F46AfaD71b8f7eaAb7B3c7aE554A86a09c6B101fa7264A0 +DAI_CONTRACT_PACKAGE=B9F554b50D64bed3AbBD50dc11D368B5682ceC62faC5b235b190b05d4be16158 + +USDC_CONTRACT=EE26EFaD06408306D167fD2DB83bf00fEef8268C50a8AAbEA8cfDF18A2C4EFB8 +USDC_CONTRACT_PACKAGE=6E3390030139474Acc0c461ab8Ddf7416A8E1112DDaB90E3A6a337B7929571E3 + +USDT_CONTRACT=077075BD6876a372cC2A60B078aD95C8B49Bd953C9C76d1b90D437Bf9c0369c3 +USDT_CONTRACT_PACKAGE=57b3af09CC84B8233CE3dDe6B16db2612e2E03fc885DFeA4626A4c56FB1C5a8E + +WETH_DAI_CONTRACT=93855DECcfcD71b5d181ECf71e1987E353EE8eF75C25ED226172a2770d38d328 +WETH_DAI_CONTRACT_PACKAGE=1D1b6671a573dFa566F75231eb058031DEf09C5c34E4Ac82C34a35fAf42cC6bf + +WETH_USDC_CONTRACT=D1aAfd97D233249aab1F8a8Bd7a9D30f411ADd645bD29Dd02fe4610300e80A31 +WETH_USDC_CONTRACT_PACKAGE=03733EECb9a6c0701c47B1B5c4926D445CE087FeFf2AE4d3d226b82C6468C7DA + +WETH_USDT_CONTRACT=e40798524C0d6F7c7a82B74Bc097e8daC114e30b1daC9CDfF91a1bCB6FDC02c1 +WETH_USDT_CONTRACT_PACKAGE=81f7788FAd812C0bCE553B38F30a279a769d712cB01a9C052C6d99959DBD6F33 + GRAPHQL=http://localhost:3000/graphql CHAIN_NAME=casper-test @@ -29,9 +51,9 @@ PAIR_MASTER_KEY_PAIR_PATH=JsClients/PAIR/keys/ MASTER_KEY_PAIR_PATH=JsClients/ROUTER/keys/ ERC20_CONTRACT_NAME=erc20 -ERC20_TOKEN_NAME=token1 -ERC20_TOKEN_SYMBOL=erc -ERC20_DECIMALS=18 +ERC20_TOKEN_NAME=USDT +ERC20_TOKEN_SYMBOL=USDT +ERC20_DECIMALS=6 ERC20_TOTAL_SUPPLY=0 PAIR_CONTRACT_NAME=pair @@ -43,8 +65,8 @@ PAIR_TOTAL_SUPPLY=0 FACTORY_CONTRACT_NAME=Factory ERC20_INSTALL_PAYMENT_AMOUNT=200000000000 -FACTORY_INSTALL_PAYMENT_AMOUNT=110000000000 -PAIR_INSTALL_PAYMENT_AMOUNT=250000000000 +FACTORY_INSTALL_PAYMENT_AMOUNT=150000000000 +PAIR_INSTALL_PAYMENT_AMOUNT=300000000000 MINT_PAYMENT_AMOUNT=5000000000 MINT_AMOUNT=2000 @@ -81,13 +103,13 @@ TOKEN_NAME=uniswap-router TOKEN_SYMBOL=DRAG TOKEN_META=origin fire,lifetime infinite -FACTORY=e135359661bd6F4D0A2f827e0e25F0B1E32bb44b538676c3aECBe543F93fc54F -WCSPR=bA8f6a73B6D548E2CAe2d572aA2F824BC46A3C06a3BBA10e3d12B015931D3f85 -LIBRARY=e0Dae7571C3dc5C957a36422c56BA0ccb8AECEC833F35e32874b75A8Ea8Ac4Db +FACTORY=202dffe0821C291870c864378c38fCE0BC4Fe7EA571341c62243e92608005BEe +WCSPR=Dd511B90c7f6eacd2F74f8A1B25305a2902e3554f7489e30ca0b19247AEAb031 +LIBRARY=a1f2C4107B70AcefDf2A7A56A9F0B3B0839880CEF70869DBf829a8b5d25C0Bf7 CONTRACT_NAME=UniSwapRouter -CONTRACT_HASH=28b10e242d640B1a549Be1Ed5597E81019C7C6F4C90c277ed605406FF47E5134 -PACKAGE_HASH=17100D7fbb04140e9739fB5ba0D71AD7a00b6f370316329Ee0553CF83783693b +CONTRACT_HASH=16031d08B9C92c20F9c702b2913091b701140371555f28323e031629F8298015 +PACKAGE_HASH=66308522273D7Bc35bB99BD7cC4fB9156A2d2B2d4B3C846762BA8FDc44A9c89a INSTALL_PAYMENT_AMOUNT=200000000000 MINT_ONE_PAYMENT_AMOUNT=2000000000 MINT_COPIES_PAYMENT_AMOUNT=100000000000 @@ -98,12 +120,12 @@ MINT_COPIES_COUNT=20 MINT_MANY_META_SIZE=5 MINT_MANY_META_COUNT=5 -TO = 20831b61f3052df217EF0e441F4D7f365757Ae81Cb4C932408621cb7bf20b1c2 +TO = a29715B3d683D5D36F46AfaD71b8f7eaAb7B3c7aE554A86a09c6B101fa7264A0 DEADLINE = 1739598100811 # add_liquidity -TOKEN_A = 20831b61f3052df217EF0e441F4D7f365757Ae81Cb4C932408621cb7bf20b1c2 -TOKEN_B = ba446757a580880faCa3B9FB52a014AB3d61C88C8B175609c44e362749D871E8 +TOKEN_A = a29715B3d683D5D36F46AfaD71b8f7eaAb7B3c7aE554A86a09c6B101fa7264A0 +TOKEN_B = 2C2DeECA03Aa772E44189F6529dcad4380C5617D9F1f3C662a48cfc10Da2588A AMOUNT_A_DESIRED = 500 AMOUNT_B_DESIRED = 600 AMOUNT_A_MIN = 250 diff --git a/JsClients/ERC20/keys/public_key.pem b/JsClients/ERC20/keys/public_key.pem index 917c8f67..5f71602a 100644 --- a/JsClients/ERC20/keys/public_key.pem +++ b/JsClients/ERC20/keys/public_key.pem @@ -1,3 +1,3 @@ -----BEGIN PUBLIC KEY----- -MCowBQYDK2VwAyEA0g+BbrV8KHj7DLeH4ES/gjY2JXQLiZFW/sq0aq1hlgk= +MCowBQYDK2VwAyEAyIk/KQZh7OKw6ssepaTb25zoOvP6M2T5W4JP5IcOgiY= -----END PUBLIC KEY----- diff --git a/JsClients/ERC20/keys/public_key_hex b/JsClients/ERC20/keys/public_key_hex index 9a12d354..bad935df 100644 --- a/JsClients/ERC20/keys/public_key_hex +++ b/JsClients/ERC20/keys/public_key_hex @@ -1 +1 @@ -01d20f816eb57c2878fb0cb787e044bf82363625740b899156fecab46aad619609 \ No newline at end of file +01c8893f290661ece2b0eacb1ea5a4dbdb9ce83af3fa3364f95b824fe4870e8226 \ No newline at end of file diff --git a/JsClients/ERC20/keys/secret_key.pem b/JsClients/ERC20/keys/secret_key.pem index 04128501..96ffa2b7 100644 --- a/JsClients/ERC20/keys/secret_key.pem +++ b/JsClients/ERC20/keys/secret_key.pem @@ -1,3 +1,3 @@ -----BEGIN PRIVATE KEY----- -MC4CAQAwBQYDK2VwBCIEICzpVj2BiY8Hffjf6n5IM711VLDzBg3XBGzyw8myD6N6 +MC4CAQAwBQYDK2VwBCIEIIB/afg6EcaiWg+RLrYRuJ8WZ0a2GuqvQwvUSjDwJ6mG -----END PRIVATE KEY----- diff --git a/JsClients/ERC20/wasm/erc20-token.wasm b/JsClients/ERC20/wasm/erc20-token.wasm index 3cbdaee5..65502775 100755 Binary files a/JsClients/ERC20/wasm/erc20-token.wasm and b/JsClients/ERC20/wasm/erc20-token.wasm differ diff --git a/JsClients/FACTORY/keys/public_key.pem b/JsClients/FACTORY/keys/public_key.pem index b8b70afd..ac37b722 100644 --- a/JsClients/FACTORY/keys/public_key.pem +++ b/JsClients/FACTORY/keys/public_key.pem @@ -1,3 +1,3 @@ -----BEGIN PUBLIC KEY----- -MCowBQYDK2VwAyEAstkU0Ajtt7Fcn1TUQ8kTPQCuMMslDBVjPEjBvgEAWZk= +MCowBQYDK2VwAyEAsLAS66aiHSfOFII7qfF/qrlaDL3ds2ERZkmAVnuU2aE= -----END PUBLIC KEY----- diff --git a/JsClients/FACTORY/keys/public_key_hex b/JsClients/FACTORY/keys/public_key_hex index b87c24b6..8368c41a 100644 --- a/JsClients/FACTORY/keys/public_key_hex +++ b/JsClients/FACTORY/keys/public_key_hex @@ -1 +1 @@ -01b2d914d008edb7b15c9f54d443c9133d00ae30cb250c15633c48c1be01005999 \ No newline at end of file +01b0b012eba6a21d27ce14823ba9f17faab95a0cbdddb36111664980567b94d9a1 \ No newline at end of file diff --git a/JsClients/FACTORY/keys/secret_key.pem b/JsClients/FACTORY/keys/secret_key.pem index 50f6ba8b..5b2b8136 100644 --- a/JsClients/FACTORY/keys/secret_key.pem +++ b/JsClients/FACTORY/keys/secret_key.pem @@ -1,3 +1,3 @@ -----BEGIN PRIVATE KEY----- -MC4CAQAwBQYDK2VwBCIEIC5xV975frbrQNoTnw8WWSGZ6ZD08J94q9Ag6fvqGKmD +MC4CAQAwBQYDK2VwBCIEIJOWsLA4eBrtuReW6+06TpsPYEk1a409ChBTQoTzzpw2 -----END PRIVATE KEY----- diff --git a/JsClients/FACTORY/src/factory.ts b/JsClients/FACTORY/src/factory.ts index 72457b81..682b43cf 100644 --- a/JsClients/FACTORY/src/factory.ts +++ b/JsClients/FACTORY/src/factory.ts @@ -185,7 +185,36 @@ class FACTORYClient { throw Error("Invalid Deploy"); } } - + public async set_white_list( + keys: Keys.AsymmetricKey, + whitelist:string, + paymentAmount: string + ) { + + const white_list = new CLByteArray( + Uint8Array.from(Buffer.from(whitelist, "hex")) + ); + + const runtimeArgs = RuntimeArgs.fromMap({ + white_list: new CLKey(white_list), + }); + + const deployHash = await contractCall({ + chainName: this.chainName, + contractHash: this.contractHash, + entryPoint: "set_white_list", + keys, + nodeAddress: this.nodeAddress, + paymentAmount, + runtimeArgs, + }); + + if (deployHash !== null) { + return deployHash; + } else { + throw Error("Invalid Deploy"); + } + } public async createPair( keys: Keys.AsymmetricKey, tokenA: String, diff --git a/JsClients/FACTORY/test/installed.ts b/JsClients/FACTORY/test/installed.ts index a685d6b9..a1121939 100644 --- a/JsClients/FACTORY/test/installed.ts +++ b/JsClients/FACTORY/test/installed.ts @@ -27,6 +27,7 @@ const { TOKEN1_CONTRACT, PAIR_CONTRACT, FACTORY_CONTRACT, + PACKAGE_HASH, GRAPHQL } = process.env; @@ -50,54 +51,54 @@ 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())); + // 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); + // 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); + // 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 - } + // 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}`); - } - } - ); + // }`, + // {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); @@ -126,18 +127,26 @@ const test = async () => { // console.log(`... Contract allpairs: ${allpairs}`); //createpair - const createpairDeployHash = await factory.createPair( + // const createpairDeployHash = await factory.createPair( + // KEYS, + // TOKEN0_CONTRACT!, + // TOKEN1_CONTRACT!, + // PAIR_CONTRACT!, + // CREATE_PAIR_PAYMENT_AMOUNT! + // ); + // console.log("... CreatePair deploy hash: ", createpairDeployHash); + + // await getDeploy(NODE_ADDRESS!, createpairDeployHash); + // console.log("... Pair created successfully"); + const set_white_list_deployHash = await factory.set_white_list( KEYS, - TOKEN0_CONTRACT!, - TOKEN1_CONTRACT!, - PAIR_CONTRACT!, + PACKAGE_HASH!, CREATE_PAIR_PAYMENT_AMOUNT! ); - console.log("... CreatePair deploy hash: ", createpairDeployHash); - - await getDeploy(NODE_ADDRESS!, createpairDeployHash); - console.log("... Pair created successfully"); + 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(); @@ -200,18 +209,18 @@ const test = async () => { // }; -// export const getPair = async (contractHash:string,TOKEN0_CONTRACT:string,TOKEN1_CONTRACT:string) => { +export const getPair = async (contractHash:string,TOKEN0_CONTRACT:string,TOKEN1_CONTRACT:string) => { -// console.log(`... Contract Hash: ${contractHash}`); + console.log(`... Contract Hash: ${contractHash}`); -// // We don't need hash- prefix so i'm removing it -// await factory.setContractHash(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}`); + //pair + let pair = await factory.getPair(TOKEN0_CONTRACT, TOKEN1_CONTRACT); + console.log(`... Pair: ${pair}`); -// return pair; + return pair; -// }; +}; diff --git a/JsClients/FACTORY/wasm/factory.wasm b/JsClients/FACTORY/wasm/factory.wasm index 77570a0f..29ed6e40 100755 Binary files a/JsClients/FACTORY/wasm/factory.wasm and b/JsClients/FACTORY/wasm/factory.wasm differ diff --git a/JsClients/PAIR/keys/public_key.pem b/JsClients/PAIR/keys/public_key.pem index 5efade20..84fe23b4 100644 --- a/JsClients/PAIR/keys/public_key.pem +++ b/JsClients/PAIR/keys/public_key.pem @@ -1,3 +1,3 @@ -----BEGIN PUBLIC KEY----- -MCowBQYDK2VwAyEAD1kE+NGCqK8ZWlbdHdZpydKs3WjAvRCjJsoK7AyLFCU= +MCowBQYDK2VwAyEA8NpIG/A3BM4sTwBpvzwd2lLSbxkOwV9EgB2zNyF+jGE= -----END PUBLIC KEY----- diff --git a/JsClients/PAIR/keys/public_key_hex b/JsClients/PAIR/keys/public_key_hex index aea141e5..8dfdaba1 100644 --- a/JsClients/PAIR/keys/public_key_hex +++ b/JsClients/PAIR/keys/public_key_hex @@ -1 +1 @@ -010f5904f8d182a8af195a56dd1dd669c9d2acdd68c0bd10a326ca0aec0c8b1425 \ No newline at end of file +01f0da481bf03704ce2c4f0069bf3c1dda52d26f190ec15f44801db337217e8c61 \ No newline at end of file diff --git a/JsClients/PAIR/keys/secret_key.pem b/JsClients/PAIR/keys/secret_key.pem index 0699d422..b3a08273 100644 --- a/JsClients/PAIR/keys/secret_key.pem +++ b/JsClients/PAIR/keys/secret_key.pem @@ -1,3 +1,3 @@ -----BEGIN PRIVATE KEY----- -MC4CAQAwBQYDK2VwBCIEIKLUePR5NlWUtM+/OGb5iQm4AkH8n2tlkUtUzSvRAVwA +MC4CAQAwBQYDK2VwBCIEICkMp/OULXfRk3vNYWtqMsfTC4YGuhtFGZd/pBCCy0G+ -----END PRIVATE KEY----- diff --git a/JsClients/PAIR/src/pair.ts b/JsClients/PAIR/src/pair.ts index 80df7b9d..41f60702 100644 --- a/JsClients/PAIR/src/pair.ts +++ b/JsClients/PAIR/src/pair.ts @@ -160,9 +160,19 @@ class PAIRClient { ); return result.value(); } - + public async balanceOf_router(account: CLPublicKey) { + const accountHash = Buffer.from(account.toAccountHash()).toString("hex"); + console.log("accoutnHash: ",accountHash); + const result = await utils.contractDictionaryGetter( + this.nodeAddress, + accountHash, + this.namedKeys.balances + ); + const maybeValue = result.value().unwrap(); + return maybeValue.value().toString(); + } public async balanceOf(accountHash: string) { - //const accountHash = Buffer.from(account.toAccountHash()).toString("hex"); + console.log("accoutnHash: ",accountHash); const result = await utils.contractDictionaryGetter( this.nodeAddress, accountHash, diff --git a/JsClients/PAIR/src/utils.ts b/JsClients/PAIR/src/utils.ts index a8fb6228..909a7d64 100644 --- a/JsClients/PAIR/src/utils.ts +++ b/JsClients/PAIR/src/utils.ts @@ -59,17 +59,10 @@ export const getAccountInfo = async ( nodeAddress: string, publicKey: CLPublicKey ) => { - // console.log("nodeAddress", nodeAddress); - // console.log("publicKey", publicKey); - const stateRootHash = await getStateRootHash(nodeAddress); - // console.log("stateRootHash", stateRootHash); const client = new CasperServiceByJsonRPC(nodeAddress); - // console.log("client", client); const accountHash = publicKey.toAccountHashStr(); - // console.log("accountHash", accountHash); const blockState = await client.getBlockState(stateRootHash, accountHash, []); - // console.log("blockState", blockState); return blockState.Account; }; diff --git a/JsClients/PAIR/test/installed.ts b/JsClients/PAIR/test/installed.ts index 22803f62..c94f0c30 100644 --- a/JsClients/PAIR/test/installed.ts +++ b/JsClients/PAIR/test/installed.ts @@ -67,253 +67,253 @@ 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); + // 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); + // 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); + // 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); + // 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 - } + // 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)); - } + // }`, + // {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 - } + // } + // 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 - } + // }`, + // {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); + // }`, + // {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 - } + // 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); + // }`, + // {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 - } + // 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 - } + // }`, + // {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)); - } + // }`, + // {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}`); - } - } - ); + // } else { + // console.log(`Failed deploy of ${eventName}, deployHash: ${deploy.deployHash}`); + // console.log(`Error: ${deploy.error}`); + // } + // } + // ); await sleep(5 * 1000); @@ -402,9 +402,9 @@ const test = async () => { // console.log(`... Total supply: ${totalSupply}`); // //balanceof - let balance = await pair.balanceOf(PAIR_CONTRACT_PACKAGE!); - //console.log(`... Balance of account ${KEYS.publicKey.toAccountHashStr()}`); - console.log(`... Balance: ${balance}`); + // let balance = await pair.balanceOf(PAIR_CONTRACT_PACKAGE!); + // //console.log(`... Balance of account ${KEYS.publicKey.toAccountHashStr()}`); + // console.log(`... Balance: ${balance}`); // //balanceof // let nonce = await pair.nonce(KEYS.publicKey); @@ -426,11 +426,10 @@ const test = async () => { // await getDeploy(NODE_ADDRESS!, erc20mint0DeployHash); // console.log("... Token minted successfully"); - - // //erc20mint - // const erc20mint1DeployHash = await pair.erc20Mint( + //erc20mint + // const erc20mint1DeployHash = await pair.erc20Mint_router( // KEYS, - // PAIR_CONTRACT_PACKAGE!, + // ROUTERKEYS.publicKey, // "2000", // MINT_PAYMENT_AMOUNT! // ); @@ -439,18 +438,25 @@ const test = async () => { // await getDeploy(NODE_ADDRESS!, erc20mint1DeployHash); // console.log("... Token minted successfully"); - //erc20mint - // const erc20mint1DeployHash = await pair.erc20Mint_router( + // //erc20mint + // const erc20mint2DeployHash = await pair.erc20Mint( // KEYS, - // ROUTERKEYS.publicKey!, + // PAIR_CONTRACT_PACKAGE!, // "2000", // MINT_PAYMENT_AMOUNT! // ); - // console.log("... Mint deploy hash: ", erc20mint1DeployHash); + // console.log("... Mint deploy hash: ", erc20mint2DeployHash); - // await getDeploy(NODE_ADDRESS!, erc20mint1DeployHash); + // await getDeploy(NODE_ADDRESS!, erc20mint2DeployHash); // console.log("... Token minted successfully"); + // //balanceof + let balance_router = await pair.balanceOf_router(ROUTERKEYS.publicKey); + console.log(`... Balance: ${balance_router}`); + //balanceof + let balance = await pair.balanceOf((PAIR_CONTRACT_PACKAGE!).toLowerCase()); + console.log(`... Balance: ${balance}`); + // //sync // const syncDeployHash = await pair.sync( // KEYS, @@ -593,7 +599,7 @@ const test = async () => { }; -test(); +//test(); export const balanceOf = async (contractHash:string, key:string) => { diff --git a/JsClients/PAIR/wasm/pair-token.wasm b/JsClients/PAIR/wasm/pair-token.wasm index a756d3dc..83aeccad 100755 Binary files a/JsClients/PAIR/wasm/pair-token.wasm and b/JsClients/PAIR/wasm/pair-token.wasm differ diff --git a/JsClients/ROUTER/keys/public_key.pem b/JsClients/ROUTER/keys/public_key.pem index 997762f4..efdd49ca 100644 --- a/JsClients/ROUTER/keys/public_key.pem +++ b/JsClients/ROUTER/keys/public_key.pem @@ -1,3 +1,3 @@ -----BEGIN PUBLIC KEY----- -MCowBQYDK2VwAyEAz2L03zDo9qgBL8DwJwWFKkHTNy7tj2w/nvRG8CUISLs= +MCowBQYDK2VwAyEAxPrtvPjJMutf5UZ9ZXi7Hpe6kAOiOv5+chnOS7Q3xog= -----END PUBLIC KEY----- diff --git a/JsClients/ROUTER/keys/public_key_hex b/JsClients/ROUTER/keys/public_key_hex index d2416696..5ad7287f 100644 --- a/JsClients/ROUTER/keys/public_key_hex +++ b/JsClients/ROUTER/keys/public_key_hex @@ -1 +1 @@ -01cf62f4df30e8f6a8012fc0f02705852a41d3372eed8f6c3f9ef446f0250848bb \ No newline at end of file +01c4faedbcf8c932eb5fe5467d6578bb1e97ba9003a23afe7e7219ce4bb437c688 \ No newline at end of file diff --git a/JsClients/ROUTER/keys/secret_key.pem b/JsClients/ROUTER/keys/secret_key.pem index a963c974..2d747d75 100644 --- a/JsClients/ROUTER/keys/secret_key.pem +++ b/JsClients/ROUTER/keys/secret_key.pem @@ -1,3 +1,3 @@ -----BEGIN PRIVATE KEY----- -MC4CAQAwBQYDK2VwBCIEINSB9zUWCLJXgm2b5Z06zwzZek9651oGKGEC63nLgqdn +MC4CAQAwBQYDK2VwBCIEIEEGMR2DKgjA/FWPa/KHyoJ80mnDachq9JzVbwIuIUw7 -----END PRIVATE KEY----- diff --git a/JsClients/ROUTER/src/uniswap-router-client.ts b/JsClients/ROUTER/src/uniswap-router-client.ts index 2a72eaff..092b9027 100644 --- a/JsClients/ROUTER/src/uniswap-router-client.ts +++ b/JsClients/ROUTER/src/uniswap-router-client.ts @@ -191,7 +191,7 @@ class UniswapRouterClient { throw Error("Invalid Deploy"); } } - + public async add_liquidity_cspr( keys: Keys.AsymmetricKey, token: string, diff --git a/JsClients/ROUTER/test/installed.ts b/JsClients/ROUTER/test/installed.ts index 791ba2b8..556d604f 100644 --- a/JsClients/ROUTER/test/installed.ts +++ b/JsClients/ROUTER/test/installed.ts @@ -528,4 +528,4 @@ const test = async () => { }; -test(); +//test(); diff --git a/JsClients/ROUTER/wasm/uniswap-v2-router.wasm b/JsClients/ROUTER/wasm/uniswap-v2-router.wasm index eb85f5e3..149cf8cf 100644 Binary files a/JsClients/ROUTER/wasm/uniswap-v2-router.wasm and b/JsClients/ROUTER/wasm/uniswap-v2-router.wasm differ diff --git a/JsClients/keys/erc20keys/public_key.pem b/JsClients/keys/erc20keys/public_key.pem new file mode 100644 index 00000000..121c420f --- /dev/null +++ b/JsClients/keys/erc20keys/public_key.pem @@ -0,0 +1,3 @@ +-----BEGIN PUBLIC KEY----- +MCowBQYDK2VwAyEAmqT9AONEBlbpbD0n5LVY0+aGb9Wk/ww4W4whlDS/GIA= +-----END PUBLIC KEY----- diff --git a/JsClients/keys/erc20keys/public_key_hex b/JsClients/keys/erc20keys/public_key_hex new file mode 100644 index 00000000..bdbf032c --- /dev/null +++ b/JsClients/keys/erc20keys/public_key_hex @@ -0,0 +1 @@ +019aa4fd00e3440656e96c3d27e4b558d3e6866fd5a4ff0c385b8c219434bf1880 \ No newline at end of file diff --git a/JsClients/keys/erc20keys/secret_key.pem b/JsClients/keys/erc20keys/secret_key.pem new file mode 100644 index 00000000..27f7bb21 --- /dev/null +++ b/JsClients/keys/erc20keys/secret_key.pem @@ -0,0 +1,3 @@ +-----BEGIN PRIVATE KEY----- +MC4CAQAwBQYDK2VwBCIEIBkogB4ZgMcSrMq20nt3xXMQs/yXH3ASt/SPSJ73jaGz +-----END PRIVATE KEY----- diff --git a/JsClients/keys/factorykeys/public_key.pem b/JsClients/keys/factorykeys/public_key.pem new file mode 100644 index 00000000..0defcdb4 --- /dev/null +++ b/JsClients/keys/factorykeys/public_key.pem @@ -0,0 +1,3 @@ +-----BEGIN PUBLIC KEY----- +MCowBQYDK2VwAyEAsLAS66aiHSfOFII7qfF/qrlaDL3ds2ERZkmAVnuU2aE= +-----END PUBLIC KEY----- diff --git a/JsClients/keys/factorykeys/public_key_hex b/JsClients/keys/factorykeys/public_key_hex new file mode 100644 index 00000000..8368c41a --- /dev/null +++ b/JsClients/keys/factorykeys/public_key_hex @@ -0,0 +1 @@ +01b0b012eba6a21d27ce14823ba9f17faab95a0cbdddb36111664980567b94d9a1 \ No newline at end of file diff --git a/JsClients/keys/factorykeys/secret_key.pem b/JsClients/keys/factorykeys/secret_key.pem new file mode 100644 index 00000000..66de9921 --- /dev/null +++ b/JsClients/keys/factorykeys/secret_key.pem @@ -0,0 +1,3 @@ +-----BEGIN PRIVATE KEY----- +MC4CAQAwBQYDK2VwBCIEIJOWsLA4eBrtuReW6+06TpsPYEk1a409ChBTQoTzzpw2 +-----END PRIVATE KEY----- diff --git a/JsClients/keys/pairkeys/public_key.pem b/JsClients/keys/pairkeys/public_key.pem new file mode 100644 index 00000000..54387a4d --- /dev/null +++ b/JsClients/keys/pairkeys/public_key.pem @@ -0,0 +1,3 @@ +-----BEGIN PUBLIC KEY----- +MCowBQYDK2VwAyEAuQuMtVUMhsVG8IcrpiamSivGmWGwbT5c/Y3g7c0UJHM= +-----END PUBLIC KEY----- diff --git a/JsClients/keys/pairkeys/public_key_hex b/JsClients/keys/pairkeys/public_key_hex new file mode 100644 index 00000000..f7f98953 --- /dev/null +++ b/JsClients/keys/pairkeys/public_key_hex @@ -0,0 +1 @@ +01b90b8cb5550c86c546f0872ba626a64a2bc69961b06d3e5cfd8de0edcd142473 \ No newline at end of file diff --git a/JsClients/keys/pairkeys/secret_key.pem b/JsClients/keys/pairkeys/secret_key.pem new file mode 100644 index 00000000..ee2b9f9a --- /dev/null +++ b/JsClients/keys/pairkeys/secret_key.pem @@ -0,0 +1,3 @@ +-----BEGIN PRIVATE KEY----- +MC4CAQAwBQYDK2VwBCIEICKLzLvu9Jf/q72EjZ4XThON5k+x7neGeJ+gR/0eqpvg +-----END PRIVATE KEY----- diff --git a/JsClients/keys/routerkeys/public_key.pem b/JsClients/keys/routerkeys/public_key.pem new file mode 100644 index 00000000..efdd49ca --- /dev/null +++ b/JsClients/keys/routerkeys/public_key.pem @@ -0,0 +1,3 @@ +-----BEGIN PUBLIC KEY----- +MCowBQYDK2VwAyEAxPrtvPjJMutf5UZ9ZXi7Hpe6kAOiOv5+chnOS7Q3xog= +-----END PUBLIC KEY----- diff --git a/JsClients/keys/routerkeys/public_key_hex b/JsClients/keys/routerkeys/public_key_hex new file mode 100644 index 00000000..5ad7287f --- /dev/null +++ b/JsClients/keys/routerkeys/public_key_hex @@ -0,0 +1 @@ +01c4faedbcf8c932eb5fe5467d6578bb1e97ba9003a23afe7e7219ce4bb437c688 \ No newline at end of file diff --git a/JsClients/keys/routerkeys/secret_key.pem b/JsClients/keys/routerkeys/secret_key.pem new file mode 100644 index 00000000..2d747d75 --- /dev/null +++ b/JsClients/keys/routerkeys/secret_key.pem @@ -0,0 +1,3 @@ +-----BEGIN PRIVATE KEY----- +MC4CAQAwBQYDK2VwBCIEIEEGMR2DKgjA/FWPa/KHyoJ80mnDachq9JzVbwIuIUw7 +-----END PRIVATE KEY----- diff --git a/JsClients/keys/stablecoinkeys/public_key.pem b/JsClients/keys/stablecoinkeys/public_key.pem new file mode 100644 index 00000000..121c420f --- /dev/null +++ b/JsClients/keys/stablecoinkeys/public_key.pem @@ -0,0 +1,3 @@ +-----BEGIN PUBLIC KEY----- +MCowBQYDK2VwAyEAmqT9AONEBlbpbD0n5LVY0+aGb9Wk/ww4W4whlDS/GIA= +-----END PUBLIC KEY----- diff --git a/JsClients/keys/stablecoinkeys/public_key_hex b/JsClients/keys/stablecoinkeys/public_key_hex new file mode 100644 index 00000000..bdbf032c --- /dev/null +++ b/JsClients/keys/stablecoinkeys/public_key_hex @@ -0,0 +1 @@ +019aa4fd00e3440656e96c3d27e4b558d3e6866fd5a4ff0c385b8c219434bf1880 \ No newline at end of file diff --git a/JsClients/keys/stablecoinkeys/secret_key.pem b/JsClients/keys/stablecoinkeys/secret_key.pem new file mode 100644 index 00000000..27f7bb21 --- /dev/null +++ b/JsClients/keys/stablecoinkeys/secret_key.pem @@ -0,0 +1,3 @@ +-----BEGIN PRIVATE KEY----- +MC4CAQAwBQYDK2VwBCIEIBkogB4ZgMcSrMq20nt3xXMQs/yXH3ASt/SPSJ73jaGz +-----END PRIVATE KEY----- diff --git a/JsClients/keys/stablecoinpairkeys/public_key.pem b/JsClients/keys/stablecoinpairkeys/public_key.pem new file mode 100644 index 00000000..579d7eb9 --- /dev/null +++ b/JsClients/keys/stablecoinpairkeys/public_key.pem @@ -0,0 +1,3 @@ +-----BEGIN PUBLIC KEY----- +MCowBQYDK2VwAyEA8NpIG/A3BM4sTwBpvzwd2lLSbxkOwV9EgB2zNyF+jGE= +-----END PUBLIC KEY----- diff --git a/JsClients/keys/stablecoinpairkeys/public_key_hex b/JsClients/keys/stablecoinpairkeys/public_key_hex new file mode 100644 index 00000000..8dfdaba1 --- /dev/null +++ b/JsClients/keys/stablecoinpairkeys/public_key_hex @@ -0,0 +1 @@ +01f0da481bf03704ce2c4f0069bf3c1dda52d26f190ec15f44801db337217e8c61 \ No newline at end of file diff --git a/JsClients/keys/stablecoinpairkeys/secret_key.pem b/JsClients/keys/stablecoinpairkeys/secret_key.pem new file mode 100644 index 00000000..23350172 --- /dev/null +++ b/JsClients/keys/stablecoinpairkeys/secret_key.pem @@ -0,0 +1,3 @@ +-----BEGIN PRIVATE KEY----- +MC4CAQAwBQYDK2VwBCIEICkMp/OULXfRk3vNYWtqMsfTC4YGuhtFGZd/pBCCy0G+ +-----END PRIVATE KEY----- diff --git a/graphql/mutations.js b/graphql/mutations.js index cf9c215d..959e953e 100644 --- a/graphql/mutations.js +++ b/graphql/mutations.js @@ -716,7 +716,7 @@ const handleTransfer = { if (from != ADDRESS_ZERO && from != pair.id) { console.log("burn2"); - let Balance =await PairContract.balanceOf(args.pairAddress,from); + let Balance =await PairContract.balanceOf(args.pairAddress,from.toLowerCase()); //let Balance=2000; await createLiquidityPosition(args.pairAddress, from, Balance); @@ -732,7 +732,7 @@ const handleTransfer = { if (to != ADDRESS_ZERO && to != pair.id) { console.log("burn3"); - let Balance =await PairContract.balanceOf(args.pairAddress,to); + let Balance =await PairContract.balanceOf(args.pairAddress,to.toLowerCase()); //let Balance=2000; await createLiquidityPosition(args.pairAddress, to, Balance); @@ -804,24 +804,24 @@ const handleSync = { // update ETH price now that reserves could have changed let bundle = await Bundle.findOne({ id: "1" }); - //bundle.ethPrice = getEthPriceInUSD(); - bundle.ethPrice = 1; //passing one Because Casper don't have the feature right now and zero gives error on the frontend + bundle.ethPrice = await getEthPriceInUSD(); + //bundle.ethPrice = 1; //passing one Because Casper don't have the feature right now and zero gives error on the frontend await bundle.save(); - // token0.derivedETH = findEthPerToken(token0); - // token1.derivedETH = findEthPerToken(token1); - token0.derivedETH = 0; //passing zero Because Casper don't have the feature right now - token1.derivedETH = 0; //passing zero Because Casper don't have the feature right now + token0.derivedETH = await findEthPerToken(token0); + token1.derivedETH = await findEthPerToken(token1); + //token0.derivedETH = 0; //passing zero Because Casper don't have the feature right now + //token1.derivedETH = 0; //passing zero Because Casper don't have the feature right now await token0.save(); await token1.save(); // get tracked liquidity - will be 0 if neither is in whitelist let trackedLiquidityETH; if (bundle.ethPrice != ZERO_BD) { - // trackedLiquidityETH = - // getTrackedLiquidityUSD(pair.reserve0, token0, pair.reserve1, token1) / - // bundle.ethPrice; - trackedLiquidityETH = 0; //passing zero Because Casper don't have the feature right now + trackedLiquidityETH = + await getTrackedLiquidityUSD(pair.reserve0, token0, pair.reserve1, token1) / + bundle.ethPrice; + //trackedLiquidityETH = 0; //passing zero Because Casper don't have the feature right now } else { trackedLiquidityETH = ZERO_BD; } @@ -1130,14 +1130,14 @@ const handleSwap = { let derivedAmountUSD = derivedAmountETH * bundle.ethPrice; // only accounts for volume through white listed tokens - // let trackedAmountUSD = getTrackedVolumeUSD( - // amount0Total, - // token0, - // amount1Total, - // token1, - // pair - // ); - let trackedAmountUSD = 0; //passing zero Because Casper don't have the feature right now + let trackedAmountUSD = await getTrackedVolumeUSD( + amount0Total, + token0, + amount1Total, + token1, + pair + ); + //let trackedAmountUSD = 0; //passing zero Because Casper don't have the feature right now let trackedAmountETH; if (bundle.ethPrice == ZERO_BD) { diff --git a/graphql/pricing.js b/graphql/pricing.js index 4ef1ce8f..e7bf534b 100644 --- a/graphql/pricing.js +++ b/graphql/pricing.js @@ -11,10 +11,10 @@ const { //UNTRACKED_PAIRS } = require("./helpers"); -const WETH_ADDRESS = "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2"; -const USDC_WETH_PAIR = "0xb4e16d0168e52d35cacd2c6185b44281ec28c9dc"; // created 10008355 -const DAI_WETH_PAIR = "0xa478c2975ab1ea89e8196811f51a7b7ade33eb11"; // created block 10042267 -const USDT_WETH_PAIR = "0x0d4a11d5eeaac28ec3f61d100daf4d40471f1852"; // created block 10093341 +const WETH_ADDRESS = "2C2DeECA03Aa772E44189F6529dcad4380C5617D9F1f3C662a48cfc10Da2588A".toLowerCase(); +const USDC_WETH_PAIR = "D1aAfd97D233249aab1F8a8Bd7a9D30f411ADd645bD29Dd02fe4610300e80A31".toLowerCase(); // created 10008355 +const DAI_WETH_PAIR = "93855DECcfcD71b5d181ECf71e1987E353EE8eF75C25ED226172a2770d38d328".toLowerCase(); // created block 10042267 +const USDT_WETH_PAIR = "e40798524C0d6F7c7a82B74Bc097e8daC114e30b1daC9CDfF91a1bCB6FDC02c1".toLowerCase(); // created block 10093341 async function getEthPriceInUSD() { // fetch eth prices for each stablecoin @@ -50,26 +50,10 @@ async function getEthPriceInUSD() { // token where amounts should contribute to tracked volume and liquidity let WHITELIST = [ - "0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2", // WETH - "0x6b175474e89094c44da98b954eedeac495271d0f", // DAI - "0xa0b86991c6218b36c1d19d4a2e9eb0ce3606eb48", // USDC - "0xdac17f958d2ee523a2206206994597c13d831ec7", // USDT - "0x0000000000085d4780b73119b644ae5ecd22b376", // TUSD - "0x5d3a536e4d6dbd6114cc1ead35777bab948e3643", // cDAI - "0x39aa39c021dfbae8fac545936693ac917d5e7563", // cUSDC - "0x86fadb80d8d2cff3c3680819e4da99c10232ba0f", // EBASE - "0x57ab1ec28d129707052df4df418d58a2d46d5f51", // sUSD - "0x9f8f72aa9304c8b593d555f12ef6589cc3a579a2", // MKR - "0xc00e94cb662c3520282e6f5717214004a7f26888", // COMP - "0x514910771af9ca656af840dff83e8264ecf986ca", //LINK - "0x960b236a07cf122663c4303350609a66a7b288c0", //ANT - "0xc011a73ee8576fb46f5e1c5751ca3b9fe0af2a6f", //SNX - "0x0bc529c00c6401aef6d220be8c6ea1667f6ad93e", //YFI - "0xdf5e0e81dff6faf3a7e52ba697820c5e32d806a8", // yCurv - "0x853d955acef822db058eb8505911ed77f175b99e", // FRAX - "0xa47c8bf37f92abed4a126bda807a7b7498661acd", // WUST - "0x1f9840a85d5af5bf1d1762f925bdaddc4201f984", // UNI - "0x2260fac5e5542a773aa44fbcfedf7c193bc2c599", // WBTC + "2C2DeECA03Aa772E44189F6529dcad4380C5617D9F1f3C662a48cfc10Da2588A".toLowerCase(), // WETH + "a29715B3d683D5D36F46AfaD71b8f7eaAb7B3c7aE554A86a09c6B101fa7264A0".toLowerCase(), // DAI + "EE26EFaD06408306D167fD2DB83bf00fEef8268C50a8AAbEA8cfDF18A2C4EFB8".toLowerCase(), // USDC + "077075BD6876a372cC2A60B078aD95C8B49Bd953C9C76d1b90D437Bf9c0369c3".toLowerCase(), // USDT ]; // minimum liquidity required to count towards tracked volume for pairs with small # of Lps @@ -90,10 +74,8 @@ async function findEthPerToken(token) { } // loop through whitelist and check if paired with any for (let i = 0; i < WHITELIST.length; ++i) { - //let pairAddress = await factory.getPair(process.env.FACTORY_CONTRACT,token.id, WHITELIST[i]); + let pairAddress = await factory.getPair(process.env.FACTORY_CONTRACT,token.id, WHITELIST[i]); - let pairAddress = - "0000000000000000000000000000000000000000000000000000000000000000"; if (pairAddress != ADDRESS_ZERO) { let pair = await Pair.findOne({ id: pairAddress }); if ( @@ -133,9 +115,9 @@ async function getTrackedVolumeUSD( let price1 = token1.derivedETH * bundle.ethPrice; // dont count tracked volume on these pairs - usually rebass tokens - if (UNTRACKED_PAIRS.includes(pair.id)) { - return ZERO_BD; - } + // if (UNTRACKED_PAIRS.includes(pair.id)) { + // return ZERO_BD; + // } // if less than 5 LPs, require high minimum reserve amount amount or return 0 if (pair.liquidityProviderCount < 5) {