Skip to content

Commit

Permalink
Merge pull request #1208 from madfish-solutions/v3.2.12
Browse files Browse the repository at this point in the history
V3.2.12
  • Loading branch information
00-22-11 authored Dec 14, 2022
2 parents 8b4f03e + e358e0b commit dfc67af
Show file tree
Hide file tree
Showing 106 changed files with 1,888 additions and 438 deletions.
2 changes: 1 addition & 1 deletion .env.ghostnet.pord
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ REACT_APP_TTDEX_CONTRACT=KT1PnmpVWmA5CBUsA5ZAx1HoDW67mPYurAL5
REACT_APP_FARMING_CONTRACT=KT1HXQcPhPtVWiU64X4WZG9dmRBhBAkAEfT1
REACT_APP_COINFLIP_CONTRACT=KT1LYJif66XPDGgvUZdnmdyorjEYHkT9pTs5
REACT_APP_STABLESWAP_FACTORY_CONTRACT_ADDRESS=KT1GjgXdwaMjjwXcS2JURcMA53WRq9qW1nZF
REACT_APP_DEX_V3_FACTORY_ADDRESS=KT1TL49GeTyi3n7q4MG4XQh1i3y9KDo6cdYB
REACT_APP_DEX_V3_FACTORY_ADDRESS=KT1Vf8ELhJQtYJNjbiKxpQUxVWBkknFKRA7Q

#network and mode depends
#temple api
Expand Down
2 changes: 1 addition & 1 deletion .env.ghostnet.stage
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ REACT_APP_FARMING_CONTRACT=KT1HXQcPhPtVWiU64X4WZG9dmRBhBAkAEfT1
REACT_APP_COINFLIP_CONTRACT=KT1LYJif66XPDGgvUZdnmdyorjEYHkT9pTs5
REACT_APP_STABLESWAP_FACTORY_CONTRACT_ADDRESS=KT1GjgXdwaMjjwXcS2JURcMA53WRq9qW1nZF
REACT_APP_DEX_TWO_CONTRACT_ADDRESS=KT1GPJDTf8GZspCcanaG2KhMvGu3NJRqurat
REACT_APP_DEX_V3_FACTORY_ADDRESS=KT1TL49GeTyi3n7q4MG4XQh1i3y9KDo6cdYB
REACT_APP_DEX_V3_FACTORY_ADDRESS=KT1Vf8ELhJQtYJNjbiKxpQUxVWBkknFKRA7Q

#network and mode depends
#temple api
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "quipuswap-webapp-2",
"version": "3.2.11",
"version": "3.2.12",
"private": true,
"scripts": {
"pre-build": "node -v && npm -v && yarn -v && node ./scripts/build.js",
Expand Down
4 changes: 3 additions & 1 deletion src/config/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export const LP_INPUT_KEY = 'lp-input';
//#endregion

//#region arrays
export const FISRT_INDEX = 0;
export const FIRST_INDEX = 0;
export const OPPOSITE_INDEX = 1;
export const LAST_INDEX = -1;
//#endregion
Expand Down Expand Up @@ -180,6 +180,7 @@ export const PRECISION_PERCENT = 1e2;
export const STABLESWAP_PRECISION_FEE = 1e10;
export const PRECISION_FACTOR = 1e12;
export const PRECISION_FACTOR_STABLESWAP_LP = 1e24;
export const FEE_BASE_POINTS_PRECISION = 1e4;

//#region default stableswap fee
export const CONTRACT_DECIMALS_PRECISION_POWER = 18; // 1e18
Expand All @@ -196,6 +197,7 @@ export const DEFAULT_STABLESWAP_STAKERS_FEE_WITH_PRECISION = new BigNumber(DEFAU

//TESTNET
export const TESTNET_EXCHANGE_RATE = 1.5;
export const TESTNET_EXCHANGE_RATE_BN = new BigNumber(TESTNET_EXCHANGE_RATE);

//Charts
export const COLORS = ['#1373E4', '#F9A605', '#2ED33E', '#FF8042'];
Expand Down
Binary file added src/images/create-efficient-pool-dark.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/images/create-efficient-pool-light.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 1 addition & 9 deletions src/modules/farming/helpers/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import {
calculateTimeDiffInMs,
calculateTimeDiffInSeconds,
defined,
fillIndexArray,
getLastElementFromArray,
isExist,
isNull,
Expand Down Expand Up @@ -61,15 +62,6 @@ export const DEFAULT_RAW_USER_INFO: IRawUsersInfoValue = {
allowances: []
};

export const fillIndexArray = (value: number): Array<BigNumber> => {
const indexArray = [];
for (let i = 0; i < value; i++) {
indexArray[i] = new BigNumber(i);
}

return indexArray;
};

const NOTHING_STAKED_VALUE = 0;

export const REWARD_PRECISION = 1e18;
Expand Down
4 changes: 2 additions & 2 deletions src/modules/farming/helpers/make-not-found-page-url.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
import { Location } from 'react-router-dom';

import { FISRT_INDEX, NOT_FOUND_LETTERS_ROUTE_NAME, SLASH } from '@config/constants';
import { FIRST_INDEX, NOT_FOUND_LETTERS_ROUTE_NAME, SLASH } from '@config/constants';
import { getRouterParts } from '@shared/helpers';

const FARM_ID_INDEX = 2;

export const makeNotFoundPageUrl = (location: Location) => {
const pathnameParts = getRouterParts(location.pathname)
.slice(FISRT_INDEX, FARM_ID_INDEX)
.slice(FIRST_INDEX, FARM_ID_INDEX)
.concat(NOT_FOUND_LETTERS_ROUTE_NAME);

return SLASH.concat(pathnameParts.join(SLASH));
Expand Down
161 changes: 161 additions & 0 deletions src/modules/liquidity/api/blockchain/v3-liquidity-pool.api.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,161 @@
import { MichelsonMapKey } from '@taquito/michelson-encoder';
import { TezosToolkit } from '@taquito/taquito';
import BigNumber from 'bignumber.js';

import { sendBatch } from '@blockchain';
import { QUIPUSWAP_REFERRAL_CODE, ZERO_AMOUNT_BN } from '@config/constants';
import { DEX_V3_FACTORY_ADDRESS } from '@config/environment';
import { getContract, getStorageInfo } from '@shared/dapp';
import { bigNumberToString, defined, getUniqArray, isExist, getTransactionDeadline } from '@shared/helpers';
import { address, BigMap, int, nat, TokensValue, WithId } from '@shared/types';

import { FeeGrowth } from '../../types';

export namespace V3LiquidityPoolApi {
export interface V3PoolTick {
fee_growth_outside: FeeGrowth;
liqudity_net: int;
n_positions: nat;
next: int;
prev: int;
seconds_outside: nat;
seconds_per_liquidity_outside: nat;
sqrt_price: nat;
tick_cumulative_outside: nat;
}

export interface V3PoolPosition {
fee_growth_inside_last: FeeGrowth;
lower_tick_index: int;
upper_tick_index: int;
owner: string;
liquidity: int;
}

type V3PoolPositionWithId = WithId<V3PoolPosition, nat>;

export interface V3PoolStorage {
constants: {
ctez_burn_fee_bps: nat;
dev_fee_bps: nat;
factory_address: nat;
fee_bps: nat;
tick_spacing: nat;
token_x: TokensValue;
token_y: TokensValue;
};
sqrt_price: nat;
liquidity: nat;
cur_tick_index: int;
fee_growth: FeeGrowth;
new_position_id: nat;
positions: BigMap<nat, V3PoolPosition>;
position_ids: BigMap<address, nat[]>;
ticks: BigMap<int, V3PoolTick>;
}

export interface PositionWithTicks extends Omit<V3PoolPosition, 'lower_tick_index' | 'upper_tick_index'> {
lower_tick: WithId<V3PoolTick, int>;
upper_tick: WithId<V3PoolTick, int>;
id: nat;
}

interface V3FactoryStorage {
pools: BigMap<nat, address>;
}

export const getPool = async (tezos: TezosToolkit, id: BigNumber) => {
const factoryStorage = await getStorageInfo<V3FactoryStorage>(tezos, DEX_V3_FACTORY_ADDRESS);
const contractAddress = defined(await factoryStorage.pools.get(id), 'contractAddress');

return {
contractAddress,
storage: await getStorageInfo<V3PoolStorage>(tezos, contractAddress)
};
};

export const claimFees = async (
tezos: TezosToolkit,
contractAddress: string,
positionsIds: BigNumber[],
accountPkh: string,
transactionDuration: BigNumber
) => {
const contract = await getContract(tezos, contractAddress);
const transactionDeadline = await getTransactionDeadline(tezos, transactionDuration);

return await sendBatch(
tezos,
positionsIds.map(id =>
contract.methods
.update_position(
id,
ZERO_AMOUNT_BN,
accountPkh,
accountPkh,
transactionDeadline,
ZERO_AMOUNT_BN,
ZERO_AMOUNT_BN,
QUIPUSWAP_REFERRAL_CODE
)
.toTransferParams()
)
);
};

const getUserPositionsIds = async (contractStorage: V3PoolStorage, accountPkh: string) => {
const { position_ids } = contractStorage;

return (await position_ids.get(accountPkh)) ?? [];
};

const getPositions = async (contractStorage: V3PoolStorage, ids: BigNumber[]): Promise<V3PoolPositionWithId[]> => {
const { positions } = contractStorage;

const positionsMap = await positions.getMultipleValues(ids);

return Array.from(positionsMap.entries())
.filter((entry): entry is [MichelsonMapKey, V3PoolPosition] => {
const [, value] = entry;

return isExist(value);
})
.map(([id, position]) => ({
...position,
id: id as BigNumber
}));
};

const getPositionsTicksMap = async (contractStorage: V3PoolStorage, positions: V3PoolPosition[]) => {
const ticksIds = getUniqArray(
positions.map(({ lower_tick_index, upper_tick_index }) => [lower_tick_index, upper_tick_index]).flat(),
bigNumberToString
);

return await contractStorage.ticks.getMultipleValues(ticksIds);
};

export const getUserPositionsWithTicks = async (
tezos: TezosToolkit,
accountPkh: string,
poolId: BigNumber
): Promise<PositionWithTicks[]> => {
const { storage: contractStorage } = await getPool(tezos, poolId);
const userPositionsIds = await getUserPositionsIds(contractStorage, accountPkh);
const userPositions = await getPositions(contractStorage, userPositionsIds);

const ticksMap = await getPositionsTicksMap(contractStorage, userPositions);

return userPositions.map(({ lower_tick_index, upper_tick_index, ...userPosition }) => ({
...userPosition,
lower_tick: {
...defined(ticksMap.get(lower_tick_index), `tick ${lower_tick_index.toFixed()}`),
id: lower_tick_index
},
upper_tick: {
...defined(ticksMap.get(upper_tick_index), `tick ${upper_tick_index.toFixed()}`),
id: upper_tick_index
}
}));
};
}
37 changes: 0 additions & 37 deletions src/modules/liquidity/api/get-v3-liquidity-item.api.ts

This file was deleted.

2 changes: 1 addition & 1 deletion src/modules/liquidity/api/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@ export * from './remove-dex-two-liquidity.api';
export * from './create-liquidity-pool.api';
export * from './get-liquidity-baker-rewards.api';
export * from './claim-liquidity-baker-rewards.api';
export * from './get-v3-liquidity-item.api';
export * from './blockchain/v3-liquidity-pool.api';
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { useContext } from 'react';
import cx from 'classnames';
import ReactSlider from 'react-slick';

import { FISRT_INDEX } from '@config/constants';
import { FIRST_INDEX } from '@config/constants';
import { ColorModes, ColorThemeContext } from '@providers/color-theme-context';
import { CFC } from '@shared/types';

Expand Down Expand Up @@ -75,10 +75,10 @@ export const HotPoolSlider: CFC<Props> = ({ poolsCount, className, children }) =

if (poolsCount < MAX_SLIDES_TO_SHOW) {
SliderSettings.slidesToShow = poolsCount;
SliderSettings.responsive[FISRT_INDEX].settings.slidesToShow = poolsCount;
SliderSettings.responsive[FIRST_INDEX].settings.slidesToShow = poolsCount;
} else {
SliderSettings.slidesToShow = MAX_SLIDES_TO_SHOW;
SliderSettings.responsive[FISRT_INDEX].settings.slidesToShow = MAX_SLIDES_TO_SHOW;
SliderSettings.responsive[FIRST_INDEX].settings.slidesToShow = MAX_SLIDES_TO_SHOW;
}

return (
Expand Down
3 changes: 3 additions & 0 deletions src/modules/liquidity/dto/tick.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ export class TickDto {
@Typed()
sqrt_price: BigNumber;

@Typed({ type: FeeGrowthDto })
fee_growth: FeeGrowthDto;

@Typed()
tick_cumulative_outside: BigNumber;
}
12 changes: 9 additions & 3 deletions src/modules/liquidity/helpers/calculate-v3-item-tvl.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
import BigNumber from 'bignumber.js';

import { isExist } from '@shared/helpers';
import { Optional } from '@shared/types';

export const calculateV3ItemTvl = (
tokenXBalance: BigNumber,
tokenYBalance: BigNumber,
tokenXExchangeRate: BigNumber,
tokenYExchangeRate: BigNumber
) => tokenXBalance.multipliedBy(tokenXExchangeRate).plus(tokenYBalance.multipliedBy(tokenYExchangeRate));
tokenXExchangeRate: Optional<BigNumber>,
tokenYExchangeRate: Optional<BigNumber>
) =>
isExist(tokenXExchangeRate) && isExist(tokenYExchangeRate)
? tokenXBalance.multipliedBy(tokenXExchangeRate).plus(tokenYBalance.multipliedBy(tokenYExchangeRate))
: null;
9 changes: 9 additions & 0 deletions src/modules/liquidity/helpers/get-current-price.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import BigNumber from 'bignumber.js';

import { DEFAULT_TOKEN_ID } from '@config/constants';
import { isEqual } from '@shared/helpers';

import { oppositeCurrentPrice } from '../pages/v3-item-page/helpers';

export const getCurrentPrice = (currentPrice: BigNumber, activeTokenIndex: number) =>
isEqual(DEFAULT_TOKEN_ID, activeTokenIndex) ? currentPrice : oppositeCurrentPrice(currentPrice);
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { DEFAULT_TOKEN_ID } from '@config/constants';
import { getSymbolsString, isEqual, RawOrMappedToken } from '@shared/helpers';
import { Nullable } from '@shared/types';

export const getSymbolsStringByActiveToken = (tokens: Array<Nullable<RawOrMappedToken>>, activeTokenIndex: number) => {
const tokenDirection = isEqual(DEFAULT_TOKEN_ID, activeTokenIndex) ? tokens : tokens.reverse();

return getSymbolsString(tokenDirection);
};
2 changes: 2 additions & 0 deletions src/modules/liquidity/helpers/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,3 +11,5 @@ export * from './sorter.helpers';
export * from './filter.helpers';
export * from './make-liquidity-operation-log-data';
export * from './calculate-v3-item-tvl';
export * from './get-current-price';
export * from './get-symbols-string-by-active-token';
8 changes: 4 additions & 4 deletions src/modules/liquidity/hooks/blockchain/use-add-liquidity.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import BigNumber from 'bignumber.js';

import { FISRT_INDEX, LP_TOKEN_DECIMALS } from '@config/constants';
import { FIRST_INDEX, LP_TOKEN_DECIMALS } from '@config/constants';
import { LP_TOKEN } from '@modules/liquidity/pages/cpmm-item/components/forms/helpers/mock-lp-token';
import { useRootStore } from '@providers/root-store-provider';
import { useAccountPkh } from '@providers/use-dapp';
Expand Down Expand Up @@ -52,12 +52,12 @@ export const useAddLiquidity = () => {
sortTokens(a.token, b.token)
);

if (isTezosToken(tokensAndAmounts[FISRT_INDEX].token)) {
if (isTezosToken(tokensAndAmounts[FIRST_INDEX].token)) {
tokensAndAmounts.reverse();
}

const shares = atomicInputAmounts[FISRT_INDEX].multipliedBy(item.totalSupply)
.dividedBy(item.tokensInfo[FISRT_INDEX].atomicTokenTvl)
const shares = atomicInputAmounts[FIRST_INDEX].multipliedBy(item.totalSupply)
.dividedBy(item.tokensInfo[FIRST_INDEX].atomicTokenTvl)
.decimalPlaces(LP_TOKEN.metadata.decimals);

const sharesWithFee = getValueWithFee(shares, item.feesRate).integerValue(BigNumber.ROUND_DOWN);
Expand Down
Loading

0 comments on commit dfc67af

Please sign in to comment.