Skip to content

Commit

Permalink
Merge pull request #1262 from madfish-solutions/v3.3.3
Browse files Browse the repository at this point in the history
V3.3.3
  • Loading branch information
00-22-11 authored Jan 23, 2023
2 parents 2e6de7d + b4da828 commit f3f2e2a
Show file tree
Hide file tree
Showing 142 changed files with 1,575 additions and 1,300 deletions.
2 changes: 1 addition & 1 deletion cypress/e2e/SSL/PoolExists.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,6 @@ describe('Specific pool exist', () => {
// check if 'back to list' arrow works
it('Should_DisplaySSLList_When_ClickOnBackArrow', () => {
cy.get('[data-test-id="stableswapFromTabsCard"] [data-test-id="backTTListButton"]').click();
cy.get('[data-test-id="SSLPageTitle"]').should('contain', 'Stableswap Liquidity');
cy.get('[data-test-id="LiquidityListTitle"]').should('contain', 'Liquidity');
});
});
16 changes: 0 additions & 16 deletions cypress/e2e/SSL/VisualTesting.spec.js

This file was deleted.

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.2",
"version": "3.3.3",
"private": true,
"scripts": {
"pre-build": "node -v && npm -v && yarn -v && node ./scripts/build.js",
Expand Down
1 change: 1 addition & 0 deletions src/config/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ export const AUTOSAVE_DEBOUNCE_MS = MS_IN_SECOND;
//#region liveable rewards time
export const FARM_REWARD_UPDATE_INTERVAL = MS_IN_SECOND;
export const FARM_USER_INFO_UPDATE_INTERVAL = 30 * MS_IN_SECOND;
export const FARMS_LIST_REWARD_UPDATE_INTERVAL = 60 * MS_IN_SECOND;
//#endregion

//#region numberInput
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,14 @@ import { isNull, toAtomic } from '@shared/helpers';
import { useConfirmOperation, useToasts } from '@shared/utils';

import { getHarvestAllParams } from '../../farming/api';
import { useStakedOnlyFarmIds } from '../../farming/hooks/use-staked-only-farm-ids';
import { useHarvestReadyFarmsIds } from '../../farming/hooks/use-harvest-ready-farms-ids';
import { getBetTokensParams } from '../api';

export const useHarvestAndRoll = () => {
const { tezos } = useRootStore();
const accountPkh = useAccountPkh();
const { showErrorToast } = useToasts();
const { getStakedOnlyFarmIds } = useStakedOnlyFarmIds();
const { getHarvestReadyFarmsIds } = useHarvestReadyFarmsIds();
const { getGamersStats } = useGamersStats();
const { loadUserLastGame } = useUserLastGame();
const { getUserPendingGame } = useUserPendingGame();
Expand All @@ -32,7 +32,7 @@ export const useHarvestAndRoll = () => {
return null;
}

const stakedOnlyFarmIds = getStakedOnlyFarmIds();
const harvestReadyFarmIds = getHarvestReadyFarmsIds();

try {
const atomicInputAmount = toAtomic(inputAmount, TEZOS_TOKEN_DECIMALS);
Expand All @@ -42,7 +42,7 @@ export const useHarvestAndRoll = () => {

const fee = network_fee;

const harvestOperationsParams = await getHarvestAllParams(tezos, stakedOnlyFarmIds, accountPkh);
const harvestOperationsParams = await getHarvestAllParams(tezos, harvestReadyFarmIds, accountPkh);

const betOperationParams = await getBetTokensParams(
tezos,
Expand Down
10 changes: 8 additions & 2 deletions src/modules/farming/api/blockchain/youves-farming.api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -66,10 +66,16 @@ export class BlockchainYouvesFarmingApi {
return await withApproveApi(tezos, contractAddress, token, accountPkh, tokenAmount, [params]);
}

static async harvest(tezos: TezosToolkit, contractAddress: string, stakeId: BigNumber.Value) {
static async makeHarvestMethod(tezos: TezosToolkit, contractAddress: string, stakeId: BigNumber.Value) {
const contract = await getWalletContract(tezos.wallet, contractAddress);

return await contract.methods.claim(new BigNumber(stakeId)).send();
return contract.methods.claim(new BigNumber(stakeId));
}

static async harvest(tezos: TezosToolkit, contractAddress: string, stakeId: BigNumber.Value) {
const harvestMethod = await BlockchainYouvesFarmingApi.makeHarvestMethod(tezos, contractAddress, stakeId);

return await harvestMethod.send();
}

static async withdraw(
Expand Down
45 changes: 24 additions & 21 deletions src/modules/farming/api/get-farming-list.api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { TezosToolkit } from '@taquito/taquito';
import { getUserTokenBalance } from '@blockchain';
import { ZERO_AMOUNT_BN } from '@config/constants';
import { TokenDto } from '@shared/dto';
import { isEmptyArray, isNull, retry, saveBigNumber } from '@shared/helpers';
import { getBlockchainTimestamp, isEmptyArray, isNull, retry, saveBigNumber, toMilliseconds } from '@shared/helpers';
import { Nullable } from '@shared/types';

import { getUserV1FarmingBalances, getUserYouvesFarmingBalances } from '../helpers';
Expand All @@ -18,14 +18,15 @@ interface FarmingBalances {
const getFarmingBalances = async (
item: FarmingListItemModel,
accountPkh: string,
tezos: TezosToolkit
tezos: TezosToolkit,
timestampMs: number
): Promise<FarmingBalances> => {
switch (item.version) {
case FarmVersion.v1:
return await getUserV1FarmingBalances(accountPkh, tezos, item);
return await getUserV1FarmingBalances(accountPkh, tezos, item, timestampMs);
case FarmVersion.v2:
case FarmVersion.v3:
return await getUserYouvesFarmingBalances(accountPkh, item, tezos);
return await getUserYouvesFarmingBalances(accountPkh, item, tezos, timestampMs);
default:
throw new Error('Unknown farm version');
}
Expand All @@ -38,26 +39,28 @@ const getMyBalances = async (token: TokenDto, accountPkh: string, tezos: TezosTo
return saveBigNumber(balanceBN, ZERO_AMOUNT_BN);
};

const mapBalance = (accountPkh: string, tezos: TezosToolkit) => async (item: FarmingListItemModel) => {
try {
const myBalance = await getMyBalances(item.stakedToken, accountPkh, tezos);
const farmingBalances: FarmingBalances = await getFarmingBalances(item, accountPkh, tezos);
const mapBalance =
(accountPkh: string, tezos: TezosToolkit, timestampMs: number) => async (item: FarmingListItemModel) => {
try {
const myBalance = await getMyBalances(item.stakedToken, accountPkh, tezos);
const farmingBalances: FarmingBalances = await getFarmingBalances(item, accountPkh, tezos, timestampMs);

return {
...item,
...farmingBalances,
myBalance
};
} catch (e) {
return {
...item,
error: (e as Error).message
};
}
};
return {
...item,
...farmingBalances,
myBalance
};
} catch (e) {
return {
...item,
error: (e as Error).message
};
}
};

const injectBalances = async (list: Array<FarmingListItemModel>, accountPkh: string, tezos: TezosToolkit) => {
const balances = await Promise.all(list.map(mapBalance(accountPkh, tezos)));
const blockTimestamp = await getBlockchainTimestamp(tezos);
const balances = await Promise.all(list.map(mapBalance(accountPkh, tezos, toMilliseconds(blockTimestamp))));

return { balances };
};
Expand Down
39 changes: 33 additions & 6 deletions src/modules/farming/api/harvest-all-assets.api.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,46 @@
import { TezosToolkit } from '@taquito/taquito';

import { FARMING_CONTRACT_ADDRESS } from '@config/environment';
import { batchOperations } from '@shared/helpers';
import { batchOperations, defined, getLastElementFromArray, getWalletContract } from '@shared/helpers';

export const harvestFarmingIds = async (tezos: TezosToolkit, farmingIds: string[], rewardsReceiver: string) => {
const farmingContract = await tezos.wallet.at(FARMING_CONTRACT_ADDRESS);
import { FarmVersion } from '../interfaces';
import { BlockchainYouvesFarmingApi } from './blockchain/youves-farming.api';

return farmingIds.map(farmingId => farmingContract.methods.harvest(farmingId, rewardsReceiver));
interface FarmingId {
id: string;
contractAddress?: string;
version: FarmVersion;
}

export const harvestFarmingIds = async (tezos: TezosToolkit, farmingIds: FarmingId[], rewardsReceiver: string) => {
const v1FarmingContract = await getWalletContract(tezos.wallet, FARMING_CONTRACT_ADDRESS);

return await Promise.all(
farmingIds.map(async ({ id, contractAddress, version }) => {
switch (version) {
case FarmVersion.v1:
return v1FarmingContract.methods.harvest(id, rewardsReceiver);
case FarmVersion.v2:
case FarmVersion.v3:
return await BlockchainYouvesFarmingApi.makeHarvestMethod(
tezos,
defined(contractAddress),
getLastElementFromArray(
await BlockchainYouvesFarmingApi.getStakesIds(tezos, rewardsReceiver, defined(contractAddress))
)
);
default:
throw new Error('Unknown farm version');
}
})
);
};

export const getHarvestAllParams = async (tezos: TezosToolkit, farmingIds: string[], rewardsReceiver: string) => {
export const getHarvestAllParams = async (tezos: TezosToolkit, farmingIds: FarmingId[], rewardsReceiver: string) => {
return (await harvestFarmingIds(tezos, farmingIds, rewardsReceiver)).map(op => op.toTransferParams());
};

export const harvestAllAssets = async (tezos: TezosToolkit, farmingIds: string[], rewardsReceiver: string) => {
export const harvestAllAssets = async (tezos: TezosToolkit, farmingIds: FarmingId[], rewardsReceiver: string) => {
const harvestParams = await harvestFarmingIds(tezos, farmingIds, rewardsReceiver);

return await (await batchOperations(tezos, harvestParams)).send();
Expand Down
2 changes: 0 additions & 2 deletions src/modules/farming/farming-router.vm.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ export const useFarmingRouterViewModel = () => {
isNull(rootStore.farmingFilterStore) ||
isNull(rootStore.farmingItemStore) ||
isNull(rootStore.farmingListStatsStore) ||
isNull(rootStore.farmingListRewardsStore) ||
isNull(rootStore.farmingListStore) ||
isNull(rootStore.coinflipStore) ||
isNull(rootStore.harvestAndRollStore) ||
Expand All @@ -25,7 +24,6 @@ export const useFarmingRouterViewModel = () => {
await Promise.all([
await rootStore.createFarmingFilterStore(),
await rootStore.createFarmingListStatsStore(),
await rootStore.createFarmingListRewardsStore(),
await rootStore.createFarmingListStore(),
await rootStore.createFarmingItemStore(),
await rootStore.createCoinflipStore(),
Expand Down
29 changes: 20 additions & 9 deletions src/modules/farming/helpers/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ import {
} from '../interfaces';
import { mapUsersInfoValue } from '../mapping';
import { FarmingItemV1Model, FarmingListItemModel } from '../models';
import { FarmingItemV1WithBalances } from '../pages/list/types';
import { FarmingItemV1WithBalances, FarmingListItemWithBalances } from '../pages/list/types';
import { YouvesFarmStakes, YouvesFarmStorage } from '../pages/youves-item/api/types';

export interface UserBalances {
Expand Down Expand Up @@ -71,7 +71,7 @@ export const fromRewardPrecision = (reward: BigNumber) => reward.dividedToIntege
export const getUserPendingRewardForFarmingV1 = (
userInfo: IUsersInfoValue,
farmingItemModel: FarmingListItemModel | FarmingItemV1Model,
timestamp: number = Date.now()
timestamp = Date.now()
) => {
const { staked: totalStaked, rewardPerSecond } = farmingItemModel;

Expand All @@ -97,7 +97,8 @@ export const getUserPendingRewardForFarmingV1 = (

export const calculateV1FarmingBalances = (
userInfo: Undefined<IFarmingListUsersInfoValueWithId>,
farmingItemModel: FarmingListItemModel
farmingItemModel: FarmingListItemModel,
timestampMs: number
) => {
if (!userInfo) {
return {
Expand All @@ -107,7 +108,7 @@ export const calculateV1FarmingBalances = (
};
}

const currentReward = getUserPendingRewardForFarmingV1(userInfo, farmingItemModel);
const currentReward = getUserPendingRewardForFarmingV1(userInfo, farmingItemModel, timestampMs);
const fullReward = getUserPendingRewardForFarmingV1(
userInfo,
farmingItemModel,
Expand Down Expand Up @@ -146,7 +147,8 @@ export const getV1FarmsUserInfo = async (
export const getUserV1FarmingBalances = async (
accountPkh: string,
tezos: TezosToolkit,
farming: FarmingListItemModel
farming: FarmingListItemModel,
timestampMs: number
) => {
const wrapStorage: FarmingContractStorageWrapper = await (
await getContract(tezos, FARMING_CONTRACT_ADDRESS)
Expand All @@ -155,15 +157,15 @@ export const getUserV1FarmingBalances = async (

const [userInfoValue] = await getV1FarmsUserInfo(storage, accountPkh, [new BigNumber(farming.id)]);

return calculateV1FarmingBalances(userInfoValue, farming);
return calculateV1FarmingBalances(userInfoValue, farming, timestampMs);
};

export const calculateYouvesFarmingRewards = (
rewardsStats: YouvesFarmRewardsStats,
farmVersion: FarmVersion,
farmRewardTokenBalance: BigNumber,
stake: Optional<YouvesFarmStakes>,
timestampMs = Date.now()
timestampMs: number
) => {
if (!isExist(stake)) {
return {
Expand Down Expand Up @@ -193,7 +195,8 @@ export const calculateYouvesFarmingRewards = (
export const getUserYouvesFarmingBalances = async (
accountPkh: string,
farming: FarmingListItemModel,
tezos: TezosToolkit
tezos: TezosToolkit,
timestampMs: number
) => {
const farmRewardTokenBalanceBN = await retry(
async () => await getUserTokenBalance(tezos, defined(farming.contractAddress), farming.rewardToken)
Expand All @@ -214,7 +217,8 @@ export const getUserYouvesFarmingBalances = async (
{ lastRewards: lastRewards.toFixed(), discFactor, vestingPeriodSeconds, staked },
farming.version,
farmRewardTokenBalance,
stake
stake,
timestampMs
);

return {
Expand All @@ -227,6 +231,13 @@ export const getUserYouvesFarmingBalances = async (
export const getUserInfoLastStakedTime = (userInfo: Nullable<IUsersInfoValue>) =>
userInfo ? new Date(userInfo.last_staked).getTime() : null;

export const shouldHarvestInBatch = ({
earnBalance,
fullRewardBalance,
version
}: Pick<FarmingListItemWithBalances, 'earnBalance' | 'fullRewardBalance' | 'version'>) =>
earnBalance?.gt(ZERO_AMOUNT_BN) && (fullRewardBalance?.eq(earnBalance) || version === FarmVersion.v1);

export const getEndTimestamp = (
farmingItem: Optional<FarmingListItemModel | FarmingItemV1WithBalances>,
lastStakedTime: Nullable<number>
Expand Down
20 changes: 10 additions & 10 deletions src/modules/farming/hooks/blockchain/use-do-harvest-all.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,31 +7,31 @@ import { amplitudeService } from '@shared/services';
import { useConfirmOperation, useToasts } from '@shared/utils';
import { useTranslation } from '@translation';

import { useFarmingListRewardsStore } from '../stores';
import { useStakedOnlyFarmIds } from '../use-staked-only-farm-ids';
import { useHarvestReadyFarmsIds } from '../use-harvest-ready-farms-ids';
import { useRewards } from '../use-rewards';

export const useDoHarvestAll = () => {
const { t } = useTranslation();
const rootStore = useRootStore();
const confirmOperation = useConfirmOperation();
const { showErrorToast } = useToasts();
const farmingListRewardsStore = useFarmingListRewardsStore();
const { getStakedOnlyFarmIds } = useStakedOnlyFarmIds();
const { getHarvestReadyFarmsIds } = useHarvestReadyFarmsIds();
const { claimablePendingRewardsInUsd } = useRewards();

const doHarvestAll = useCallback(async () => {
const stakedOnlyFarmIds = getStakedOnlyFarmIds();
const fullClaimableRewardsFarmIds = getHarvestReadyFarmsIds();
const logData = {
harvestAll: {
farmingIds: stakedOnlyFarmIds,
rewardsInUsd: Number(farmingListRewardsStore.getUserRewardsLogData(stakedOnlyFarmIds).toFixed())
farmingIds: fullClaimableRewardsFarmIds,
rewardsInUsd: defined(claimablePendingRewardsInUsd).toNumber()
}
};

try {
amplitudeService.logEvent('HARVEST_ALL', logData);
const operation = await harvestAllAssets(
defined(rootStore.tezos),
stakedOnlyFarmIds,
fullClaimableRewardsFarmIds,
defined(rootStore.authStore.accountPkh)
);

Expand All @@ -42,8 +42,8 @@ export const useDoHarvestAll = () => {
amplitudeService.logEvent('HARVEST_ALL_FAILED', { ...logData, error });
}
}, [
getStakedOnlyFarmIds,
farmingListRewardsStore,
getHarvestReadyFarmsIds,
claimablePendingRewardsInUsd,
rootStore.tezos,
rootStore.authStore.accountPkh,
confirmOperation,
Expand Down
1 change: 1 addition & 0 deletions src/modules/farming/hooks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,4 @@ export * from './loaders';
export * from './stores';
export * from './use-harvest-confirmation-popup';
export * from './use-filtered-farming-list';
export * from './use-rewards';
1 change: 0 additions & 1 deletion src/modules/farming/hooks/stores/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,3 @@ export * from './use-farming-list.store';
export * from './use-farming-youves-item-store';
export * from './use-harvest-and-roll-store';
export * from './use-farming-list-stats-store';
export * from './use-farming-list-rewards-store';
Loading

0 comments on commit f3f2e2a

Please sign in to comment.