From d0ed0204a0a4afad264069f693196a9b453b2b4a Mon Sep 17 00:00:00 2001 From: Hammad-Mubeen Date: Fri, 22 Oct 2021 03:22:15 +0500 Subject: [PATCH] pair balanceof helper, factory getpair helper updated --- JsClients/FACTORY/test/installed.ts | 2 +- JsClients/PAIR/test/installed.ts | 6 ++++-- graphql/mutations.js | 12 ++++-------- graphql/pricing.js | 2 +- 4 files changed, 10 insertions(+), 12 deletions(-) diff --git a/JsClients/FACTORY/test/installed.ts b/JsClients/FACTORY/test/installed.ts index ef764528..50bff459 100644 --- a/JsClients/FACTORY/test/installed.ts +++ b/JsClients/FACTORY/test/installed.ts @@ -149,7 +149,7 @@ export const getPair = async (contractHash:string,TOKEN0_CONTRACT:string,TOKEN1_ console.log(`... Contract Hash: ${contractHash}`); // We don't need hash- prefix so i'm removing it - await factory.setContractHash(contractHash.slice(5)); + await factory.setContractHash(contractHash); //pair let pair = await factory.getPair(TOKEN0_CONTRACT, TOKEN1_CONTRACT); diff --git a/JsClients/PAIR/test/installed.ts b/JsClients/PAIR/test/installed.ts index c56ac352..b6a7aad4 100644 --- a/JsClients/PAIR/test/installed.ts +++ b/JsClients/PAIR/test/installed.ts @@ -320,13 +320,15 @@ const test = async () => { //test(); -export const balanceOf = async (contractHash:string,key:string) => { +export const balanceOf = async (contractHash:string, key:string) => { console.log(`... Contract Hash: ${contractHash}`); // We don't need hash- prefix so i'm removing it - await pair.setContractHash(contractHash.slice(5)); + await pair.setContractHash(contractHash); + //how to convert string into AccountHash + //balanceof //let balance = await pair.balanceOf(key); //console.log(`... Balance of account ${key.toAccountHashStr()}`); diff --git a/graphql/mutations.js b/graphql/mutations.js index e78e7914..fc0b7a64 100644 --- a/graphql/mutations.js +++ b/graphql/mutations.js @@ -414,11 +414,9 @@ const handleTransfer = { } if (from != ADDRESS_ZERO && from != pair.id) { + //let Balance =await PairContract.balanceOf(event.address,from); createLiquidityPosition(address, from, args.value); - // fromUserLiquidityPosition.liquidityTokenBalance = convertTokenToDecimal( - // pairContract.balanceOf(event.address,from), - // BI_18 - // ); + let fromUserLiquidityPosition = null; while (fromUserLiquidityPosition == null) { fromUserLiquidityPosition = await LiquidityPosition.findOne({ @@ -430,11 +428,9 @@ const handleTransfer = { } if (to != ADDRESS_ZERO && to != pair.id) { + //let Balance = await PairContract.balanceOf(event.address,to); createLiquidityPosition(address, to, args.value); - // toUserLiquidityPosition.liquidityTokenBalance = convertTokenToDecimal( - // pairContract.balanceOf(event.address,to), - // BI_18 - // ); + let toUserLiquidityPosition = null; while (toUserLiquidityPosition == null) { toUserLiquidityPosition = await LiquidityPosition.findOne({ diff --git a/graphql/pricing.js b/graphql/pricing.js index 23e0f610..fddcd0a7 100644 --- a/graphql/pricing.js +++ b/graphql/pricing.js @@ -90,7 +90,7 @@ async function findEthPerToken(token) { } // loop through whitelist and check if paired with any for (let i = 0; i < WHITELIST.length; ++i) { - //let pairAddress = factoryContract.getPair(process.env.FACTORY_ADDRESS,Address.fromString(token.id), Address.fromString(WHITELIST[i])); + //let pairAddress = await factory.getPair(process.env.FACTORY_ADDRESS,token.id, WHITELIST[i]); let pairAddress = "hash-0000000000000000000000000000000000000000000000000000000000000000";