Skip to content

Commit

Permalink
Merge branch 'develop' into QUIPU-813-zero-min-out-error-when-changin…
Browse files Browse the repository at this point in the history
…g-low-amount-in-v-3-pools-and-slippage-is-not-0
  • Loading branch information
keshan3262 authored Feb 23, 2023
2 parents 177f1f1 + a1e7260 commit 9542332
Show file tree
Hide file tree
Showing 76 changed files with 1,370 additions and 454 deletions.
3 changes: 3 additions & 0 deletions .env.mainnet.prod
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ REACT_APP_POOLS_URL=wss://dexes-api-mainnet.prod.templewallet.com/
REACT_APP_FARMING_API_URL=https://staking-api-mainnet.prod.quipuswap.com
REACT_APP_STABLESWAP_API_URL=https://stableswap-api-mainnet.prod.quipuswap.com
REACT_APP_LIQUIDITY_API_URL=https://liquidity-api-mainnet.prod.quipuswap.com
REACT_APP_THREE_ROUTE_API_URL=https://quipuswap.3route.io
REACT_APP_THREE_ROUTE_API_AUTH_TOKEN=***REMOVED***
REACT_APP_THREE_ROUTE_CONTRACT_ADDRESS=KT1Tuta6vbpHhZ15ixsYD3qJdhnpEAuogLQ9

#sentry
REACT_APP_SENTRY_DSN=***REMOVED***
Expand Down
3 changes: 3 additions & 0 deletions .env.mainnet.stage
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ REACT_APP_POOLS_URL=wss://dexes-api-mainnet.stage.madfish.xyz/
REACT_APP_FARMING_API_URL=https://staking-api-mainnet.stage.madfish.xyz
REACT_APP_STABLESWAP_API_URL=https://stableswap-api-mainnet.stage.madfish.xyz
REACT_APP_LIQUIDITY_API_URL=https://liquidity-api-mainnet.stage.madfish.xyz
REACT_APP_THREE_ROUTE_API_URL=https://quipuswap.3route.io
REACT_APP_THREE_ROUTE_API_AUTH_TOKEN=***REMOVED***
REACT_APP_THREE_ROUTE_CONTRACT_ADDRESS=KT1Tuta6vbpHhZ15ixsYD3qJdhnpEAuogLQ9

#TZKT
REACT_APP_TZKT_API=https://api.ghostnet.tzkt.io/v1
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.3.5",
"version": "3.3.6",
"private": true,
"scripts": {
"pre-build": "node -v && npm -v && yarn -v && node ./scripts/build.js",
Expand Down
3 changes: 3 additions & 0 deletions src/config/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -131,3 +131,6 @@ export const HOT_POOLS: Array<{ id: string; type: PoolType }> = [
// Coinflip
export const COINFLIP_CONTRACT_DECIMALS = 18;
export const COINFLIP_TOKEN_DECIMALS = 6;

// 3route
export const THREE_ROUTE_APP_ID = 3;
3 changes: 3 additions & 0 deletions src/config/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,9 @@ export const USD_DECIMALS = 2;

export const MAX_ITEMS_PER_PAGE = 5;
export const MAX_HOPS_COUNT = 3;
export const PRICE_IMPACT_WARNING_THRESHOLD = 10;

export const DATA_TEST_ID_PROP_NAME = 'data-test-id';

export const NO_WITHDRAWAL_FEE_VALUE = 0;

Expand Down
3 changes: 3 additions & 0 deletions src/config/environment.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,9 @@ export const STABLESWAP_FACTORY_CONTRACT_ADDRESS = process.env.REACT_APP_STABLES
export const TEMPLEWALLET_API_URL = process.env.REACT_APP_TEMPLEWALLET_API_URL!;
export const METADATA_API = process.env.REACT_APP_METADATA_API_URL!;
export const DEX_POOL_URL = process.env.REACT_APP_POOLS_URL!;
export const THREE_ROUTE_API_URL = process.env.REACT_APP_THREE_ROUTE_API_URL;
export const THREE_ROUTE_API_AUTH_TOKEN = process.env.REACT_APP_THREE_ROUTE_API_AUTH_TOKEN;
export const THREE_ROUTE_CONTRACT_ADDRESS = process.env.REACT_APP_THREE_ROUTE_CONTRACT_ADDRESS;

export const FARMING_API_URL = process.env.REACT_APP_FARMING_API_URL!;
export const STABLESWAP_API_URL = process.env.REACT_APP_STABLESWAP_API_URL!;
Expand Down
32 changes: 27 additions & 5 deletions src/modules/farming/helpers/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,15 @@ import { TezosToolkit } from '@taquito/taquito';
import { BigNumber } from 'bignumber.js';

import { getUserTokenBalance } from '@blockchain';
import { PRECISION_FACTOR, PRECISION_FACTOR_STABLESWAP_LP, SECONDS_IN_DAY, ZERO_AMOUNT_BN } from '@config/constants';
import {
HOURS_IN_DAY,
PRECISION_FACTOR,
PRECISION_FACTOR_STABLESWAP_LP,
SECONDS_IN_DAY,
SECONDS_IN_MINUTE,
MINUTES_IN_HOUR,
ZERO_AMOUNT_BN
} from '@config/constants';
import { FARMING_CONTRACT_ADDRESS } from '@config/environment';
import { Tzkt } from '@shared/api';
import { getContract, getStorageInfo } from '@shared/dapp';
Expand Down Expand Up @@ -200,7 +208,8 @@ export const calculateYouvesFarmingRewards = (
farmVersion: FarmVersion,
farmRewardTokenBalance: BigNumber,
stake: Optional<YouvesFarmStakes>,
timestampMs: number
timestampMs: number,
rewardsPerDay: BigNumber
) => {
if (!isExist(stake)) {
return {
Expand All @@ -221,10 +230,21 @@ export const calculateYouvesFarmingRewards = (
calculateTimeDiffInSeconds(new Date(ageTimestamp), new Date(timestampMs)),
vestingPeriodSeconds
);

const futureFarmRewardTokenBalance = farmRewardTokenBalance.plus(
vestingPeriodSeconds
.minus(stakeAge)
.dividedToIntegerBy(SECONDS_IN_MINUTE * MINUTES_IN_HOUR)
.times(rewardsPerDay.dividedToIntegerBy(HOURS_IN_DAY))
);
const futureReward = futureFarmRewardTokenBalance.minus(lastRewards);
const futureNewDiscFactor = discFactor.plus(futureReward.multipliedBy(precision).dividedToIntegerBy(totalStaked));

const fullReward = stakeAmount.times(newDiscFactor.minus(userDiscFactor)).dividedToIntegerBy(precision);
const claimableReward = fullReward.times(stakeAge).dividedToIntegerBy(vestingPeriodSeconds);
const futureFullReward = stakeAmount.times(futureNewDiscFactor.minus(userDiscFactor)).dividedToIntegerBy(precision);

return { claimableReward, fullReward };
return { claimableReward, fullReward: futureFullReward };
};

const TOKEN_BALANCE_RETRY_TIMES = 3;
Expand All @@ -248,14 +268,16 @@ export const getUserYouvesFarmingBalances = async (
last_rewards: lastRewards,
disc_factor: discFactor,
max_release_period: vestingPeriodSeconds,
total_stake: staked
total_stake: staked,
expected_rewards: rewardsPerDay
} = await getStorageInfo<YouvesFarmStorage>(tezos, farmAddress);
const { claimableReward, fullReward } = calculateYouvesFarmingRewards(
{ lastRewards: lastRewards.toFixed(), discFactor, vestingPeriodSeconds, staked },
farming.version,
farmRewardTokenBalance,
stake,
timestampMs
timestampMs,
rewardsPerDay
);

return {
Expand Down
2 changes: 1 addition & 1 deletion src/modules/farming/hooks/blockchain/use-do-harvest-all.ts
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ export const useDoHarvestAll = () => {
defined(rootStore.authStore.accountPkh)
);

await confirmOperation(operation.opHash, { message: t('farm|Stake successful') });
await confirmOperation(operation.opHash, { message: t('farm|Harvest successful') });
amplitudeService.logEvent('HARVEST_ALL_SUCCESS', logData);
} catch (error) {
showErrorToast(error as Error);
Expand Down
1 change: 1 addition & 0 deletions src/modules/farming/pages/youves-item/api/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ export interface YouvesFarmStorage {
stakes: BigMap<nat, YouvesFarmStakes>;
stakes_owner_lookup: BigMap<address, nat[]>;
total_stake: BigNumber;
expected_rewards: BigNumber;
}

export interface YouvesFarmStakes {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { Link } from 'react-router-dom';

import { AppRootRoutes } from '@app.router';
import { ColorModes, ColorThemeContext } from '@providers/color-theme-context';
import { StateCurrencyAmount, BackToListRewardHeader } from '@shared/components';
import { StateCurrencyAmount, CardHeaderWithBackButton } from '@shared/components';
import { Nullable } from '@shared/types';
import { useTranslation } from '@translation';

Expand Down Expand Up @@ -79,7 +79,7 @@ export const YouvesRewardInfoView: FC<Props> = observer(
longTermRewardsLoading={longTermRewardsLoading}
className={cx(styles.rewardInfo, modeClass[colorThemeMode])}
header={{
content: <BackToListRewardHeader backHref={AppRootRoutes.Farming} />,
content: <CardHeaderWithBackButton backHref={AppRootRoutes.Farming} text={t('common|Back to the list')} />,
className: styles.rewardHeader
}}
footer={<NextRewardsTimer />}
Expand Down
16 changes: 13 additions & 3 deletions src/modules/farming/store/farming-youves-item.store.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import {
ZERO_AMOUNT_BN
} from '@config/constants';
import { DexLink } from '@modules/liquidity/helpers';
import { getLastElement, isExist, isNull, MakeInterval, toReal } from '@shared/helpers';
import { getLastElement, isExist, isNull, MakeInterval, toAtomic, toReal, toRealIfPossible } from '@shared/helpers';
import { Led, ModelBuilder } from '@shared/model-builder';
import { LoadingErrorData, RootStore } from '@shared/store';
import { Nullable, Token } from '@shared/types';
Expand Down Expand Up @@ -50,7 +50,16 @@ export class FarmingYouvesItemStore {
readonly itemStore: LoadingErrorData<YouvesFarmingItemResponseModel, typeof DEFAULT_ITEM>;

get item() {
return this.itemStore.model.item;
const { item } = this.itemStore.model;
const currentStakeRealBalance = toRealIfPossible(this.currentStakeBalance, item?.stakedToken);

return (
item && {
...item,
tvlInStakedToken: BigNumber.maximum(item.tvlInStakedToken, currentStakeRealBalance ?? ZERO_AMOUNT_BN),
staked: BigNumber.maximum(item.staked, this.currentStakeBalance ?? ZERO_AMOUNT_BN)
}
);
}

get investHref() {
Expand Down Expand Up @@ -140,7 +149,8 @@ export class FarmingYouvesItemStore {
this.version,
this.contractBalance,
this.currentStake,
Date.now()
Date.now(),
toAtomic(this.item.dailyDistribution, this.item.rewardToken)
);

this.claimableRewards = toReal(claimableReward, this.item.rewardToken);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { AppRootRoutes } from '@app.router';
import {
AlarmMessage,
Button,
Card,
CardHeaderWithBackButton,
ConnectWalletOrDoSomething,
Iterator,
RadioButton,
Expand All @@ -22,34 +24,42 @@ export const CreatePoolForm = () => {
alarmMessageInfo,
translation,
tokensSelectData,
tokens,
quoteToken,
radioButtonParams,
disabled,
isSubmitting,
initialPriceLabel,
initialPriceValue,
initialPriceError,
setInitialPriceValue,
onSubmit,
warningMessage,
errorMessage
errorMessage,
tokensSwitcher
} = useCreatePoolFormViewModel();

const { create, initialPrice, feeRates } = translation;
const { create, feeRates } = translation;
const { poolExists, poolLink } = alarmMessageInfo;

return (
<Card contentClassName={styles.content}>
<Card
contentClassName={styles.content}
header={{
content: <CardHeaderWithBackButton backHref={AppRootRoutes.Liquidity} />,
button: tokensSwitcher
}}
>
<form className={styles.form} onSubmit={onSubmit}>
<div>
<Iterator render={TokenSelect} data={tokensSelectData} separator={<Plus className={styles.svg} />} />
</div>

<TokenInput
value={initialPriceValue}
label={initialPrice}
label={initialPriceLabel}
hiddenPercentSelector
hiddenBalance
tokens={tokens}
tokens={quoteToken}
error={initialPriceError}
onInputChange={setInitialPriceValue}
/>
Expand Down
Loading

0 comments on commit 9542332

Please sign in to comment.