From aa92042630c85a8a0bc4ab6e51ed9a09d6530af7 Mon Sep 17 00:00:00 2001 From: Digberi Date: Wed, 13 Sep 2023 16:45:47 +0300 Subject: [PATCH 1/4] fix dividends --- .../api/blockchain/stabledividends/get-staker-info.api.ts | 6 ++++-- src/shared/helpers/index.ts | 1 + src/shared/helpers/resolve-or-null.ts | 7 +++++++ 3 files changed, 12 insertions(+), 2 deletions(-) create mode 100644 src/shared/helpers/resolve-or-null.ts diff --git a/src/modules/stableswap/api/blockchain/stabledividends/get-staker-info.api.ts b/src/modules/stableswap/api/blockchain/stabledividends/get-staker-info.api.ts index e866a7ff9..96ad5ccc2 100644 --- a/src/modules/stableswap/api/blockchain/stabledividends/get-staker-info.api.ts +++ b/src/modules/stableswap/api/blockchain/stabledividends/get-staker-info.api.ts @@ -3,7 +3,7 @@ import BigNumber from 'bignumber.js'; import { DEFAULT_STABLESWAP_POOL_ID, STABLESWAP_DIVIDENDS_ACCUM_PRECISION, ZERO_AMOUNT } from '@config/constants'; import { getStorageInfo } from '@shared/dapp/get-storage-info'; -import { isExist, isNull, toArray } from '@shared/helpers'; +import { isExist, isNull, resolveOrNull, toArray } from '@shared/helpers'; import { nat, Nullable } from '@shared/types'; import { earningsMapSchema, rewardMapSchema } from '../../../schemas/get-staker-info.schemas'; @@ -49,7 +49,9 @@ const getSinglePoolStakerInfo = async ( ) => { const { storage } = await getStorageInfo(tezos, contractAddress); const { pools, stakers_balance } = storage; - const stakerAccum = (await stakers_balance.get([accountPkh, poolId])) ?? { + const _stakerAccum = await resolveOrNull(stakers_balance.get([accountPkh, poolId])); + + const stakerAccum = _stakerAccum ?? { balance: new BigNumber(ZERO_AMOUNT), earnings: new MichelsonMap(earningsMapSchema) }; diff --git a/src/shared/helpers/index.ts b/src/shared/helpers/index.ts index eb698cdee..0125512d0 100644 --- a/src/shared/helpers/index.ts +++ b/src/shared/helpers/index.ts @@ -72,3 +72,4 @@ export * from './math'; export * from './get-precentage-from-number'; export * from './set-caret-position'; export * from './can-use-three-route-api'; +export * from './resolve-or-null'; diff --git a/src/shared/helpers/resolve-or-null.ts b/src/shared/helpers/resolve-or-null.ts new file mode 100644 index 000000000..d08e73b98 --- /dev/null +++ b/src/shared/helpers/resolve-or-null.ts @@ -0,0 +1,7 @@ +export const resolveOrNull = async (value: Promise): Promise => { + try { + return await value; + } catch (e) { + return null; + } +}; From 0a020382df0483e2009d0ce609d85ccb5b36bce4 Mon Sep 17 00:00:00 2001 From: Digberi Date: Wed, 13 Sep 2023 17:14:43 +0300 Subject: [PATCH 2/4] fix v1 dex pulling --- .../pages/liquidity/hooks/helpers/find-dex.ts | 53 +++++++++++++++++++ .../liquidity/hooks/helpers/load-tez-dex.ts | 3 +- 2 files changed, 55 insertions(+), 1 deletion(-) create mode 100644 src/modules/liquidity/pages/liquidity/hooks/helpers/find-dex.ts diff --git a/src/modules/liquidity/pages/liquidity/hooks/helpers/find-dex.ts b/src/modules/liquidity/pages/liquidity/hooks/helpers/find-dex.ts new file mode 100644 index 000000000..255d906c5 --- /dev/null +++ b/src/modules/liquidity/pages/liquidity/hooks/helpers/find-dex.ts @@ -0,0 +1,53 @@ +import { + chooseDex, + ContractOrAddress, + DexNotFoundError, + Factories, + FoundDex, + isFA2Token, + Token as QuipuswapSdkToken, + toContract, + toContractAddress +} from '@quipuswap/sdk'; +import { TezosToolkit } from '@taquito/taquito'; + +import { resolveOrNull } from '@shared/helpers'; + +export async function findDex( + tezos: TezosToolkit, + { fa1_2Factory, fa2Factory }: Factories, + token: QuipuswapSdkToken +): Promise { + let factories = isFA2Token(token) ? fa2Factory : fa1_2Factory; + if (!Array.isArray(factories)) { + factories = [factories]; + } + + const tokenAddress = toContractAddress(token.contract); + const t2dexQuery = isFA2Token(token) ? [tokenAddress, token.id] : tokenAddress; + + const dexes: FoundDex[] = []; + await Promise.all( + factories.map(async factory => { + const facContract = await toContract(tezos, factory); + // eslint-disable-next-line @typescript-eslint/no-explicit-any + const facStorage = await facContract.storage(); + const dexAddress = await resolveOrNull(facStorage.token_to_exchange.get(t2dexQuery)); + + if (dexAddress) { + const dexContract = await toContract(tezos, dexAddress as ContractOrAddress); + // eslint-disable-next-line @typescript-eslint/no-explicit-any + const dexStorage = await dexContract.storage(); + dexes.push(new FoundDex(dexContract, dexStorage)); + } + }) + ); + + if (dexes.length > 1) { + return dexes.sort(chooseDex)[0]; + } else if (dexes.length === 1) { + return dexes[0]; + } else { + throw new DexNotFoundError(); + } +} diff --git a/src/modules/liquidity/pages/liquidity/hooks/helpers/load-tez-dex.ts b/src/modules/liquidity/pages/liquidity/hooks/helpers/load-tez-dex.ts index 239859039..8a111acb5 100644 --- a/src/modules/liquidity/pages/liquidity/hooks/helpers/load-tez-dex.ts +++ b/src/modules/liquidity/pages/liquidity/hooks/helpers/load-tez-dex.ts @@ -1,9 +1,10 @@ -import { findDex, FoundDex, Token as QuipuswapSdkToken } from '@quipuswap/sdk'; +import { FoundDex, Token as QuipuswapSdkToken } from '@quipuswap/sdk'; import { TezosToolkit } from '@taquito/taquito'; import { FACTORIES } from '@config/config'; import { Nullable, SupportedNetworks, Token } from '@shared/types'; +import { findDex } from './find-dex'; import { findNotTezToken } from '../../liquidity-cards/helpers'; export const loadTezDex = async ({ From 96fc7164303dc87c7f6712416ca6a0682983e314 Mon Sep 17 00:00:00 2001 From: Digberi Date: Wed, 13 Sep 2023 17:28:22 +0300 Subject: [PATCH 3/4] add babel configuration --- craco.config.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/craco.config.js b/craco.config.js index 5957a3b9a..43505c1ba 100644 --- a/craco.config.js +++ b/craco.config.js @@ -9,7 +9,9 @@ module.exports = { plugins: [ 'babel-plugin-transform-typescript-metadata', ['@babel/plugin-proposal-decorators', { legacy: true }], - ['@babel/plugin-proposal-class-properties', { loose: true }] + ['@babel/plugin-proposal-class-properties', { loose: true }], + ['@babel/plugin-transform-private-property-in-object', { loose: true }], + ['@babel/plugin-transform-private-methods', { loose: true }] ], loaderOptions: babelLoaderOptions => { return babelLoaderOptions; From edeef67e39b8cac175416e6ad3ddad2f926193e4 Mon Sep 17 00:00:00 2001 From: Digberi Date: Wed, 13 Sep 2023 17:45:04 +0300 Subject: [PATCH 4/4] v3.4.1 --- package.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/package.json b/package.json index a08a3e82f..a8572656a 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "quipuswap-webapp-2", - "version": "3.4.0", + "version": "3.4.1", "private": true, "scripts": { "pre-build": "node -v && npm -v && yarn -v && node ./scripts/build.js",