Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Release hotfix to main #1394

Merged
merged 5 commits into from
Oct 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file removed public/images/dapp_promotions/age_of_chronos.png
Binary file not shown.
5 changes: 4 additions & 1 deletion src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ import {
import { setCurrentWallet } from 'src/v2/app.container';
import { container } from 'src/v2/common';
import { Symbols } from 'src/v2/symbols';
import { useAccount, useAppRouter } from 'src/hooks';
import { useAccount, useAppRouter, useBlockTime } from 'src/hooks';
import { ETHEREUM_EXTENSION } from 'src/modules/account';
import { LOCAL_STORAGE } from 'src/config/localStorage';
import {
Expand Down Expand Up @@ -98,6 +98,7 @@ export default defineComponent({
} = useDappStaking();
const { fetchStakeAmountsToStore, fetchDappsToStore } = useDapps();
const { fetchActiveConfigurationToStore, fetchInflationParamsToStore } = useInflation();
const { fetchBlockTimeToStore } = useBlockTime();
const isLoading = computed(() => store.getters['general/isLoading']);
const showAlert = computed(() => store.getters['general/showAlert']);
const isEthWallet = computed<boolean>(() => store.getters['general/isEthWallet']);
Expand Down Expand Up @@ -150,6 +151,8 @@ export default defineComponent({
.get<IDappStakingRepositoryV3>(Symbols.DappStakingRepositoryV3)
.startProtocolStateSubscription();
}

fetchBlockTimeToStore();
});

eventAggregator.subscribe(ProtocolStateChangedMessage.name, async (m) => {
Expand Down
2 changes: 2 additions & 0 deletions src/constants.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ export enum HttpCodes {
NotFound = 404,
}

export const ORIGINAL_BLOCK_TIME = 12;

export const PERIOD1_START_BLOCKS = new Map<string, number>([
['astar', 5514935],
['shiden', 5876079],
Expand Down
6 changes: 0 additions & 6 deletions src/data/dapp_promotions.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,12 +47,6 @@
"link": "https://www.apexchimpz.com/dapp-on-astar",
"img": "images/dapp_promotions/apeXchimpz.jpg"
},
{
"name": "Age Of Chronos",
"shortDescription": "Stake and earn FREE $Astr and nfts! Play and craft NFTs 2.0!",
"link": "https://twitter.com/SFY_Labs",
"img": "images/dapp_promotions/age_of_chronos.png"
},
{
"name": "Algem - Liquid Staking",
"shortDescription": "Receive one liquid nASTR token for every ASTR token you stake. Then use nASTR to yield farm on the ecosystem to maximize your earnings.",
Expand Down
1 change: 1 addition & 0 deletions src/hooks/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,4 @@ export * from './bridge/useLayerZeroBridge';
export * from './useTokenDistribution';
export * from './useTokenCirculation';
export * from './useInflation';
export * from './useBlockTime';
20 changes: 20 additions & 0 deletions src/hooks/useBlockTime.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { computed } from 'vue';
import { useStore } from 'src/store';
import { container } from 'src/v2/common';
import { ISystemRepository } from 'src/v2/repositories';
import { Symbols } from 'src/v2/symbols';

export function useBlockTime() {
const store = useStore();
const blockTimeInSeconds = computed<number | undefined>(
() => store.getters['general/getBlockTimeInSeconds']
);

const fetchBlockTimeToStore = async () => {
const systemRepository = container.get<ISystemRepository>(Symbols.SystemRepository);
const blockTime = await systemRepository.getBlockTimeInSeconds();
store.commit('general/setBlockTime', blockTime);
};

return { blockTimeInSeconds, fetchBlockTimeToStore };
}
33 changes: 26 additions & 7 deletions src/staking-v3/components/ClaimAndRestakeButton.vue
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@
<script lang="ts">
import { defineComponent, ref, computed } from 'vue';
import ModalRestake from './vote/re-stake/ModalRestake.vue';
import { useDappStaking, useVote } from '../hooks';
import { ClaimType } from '../logic';
import { useDappStaking, useVote, useDapps } from '../hooks';
import { ClaimType, type SingularStakingInfo } from '../logic';

export default defineComponent({
components: {
Expand Down Expand Up @@ -53,30 +53,49 @@ export default defineComponent({
claimStakerAndBonusRewards,
} = useDappStaking();
const { vote } = useVote(ref([]));
const { getDapp } = useDapps();
const showRestakeModal = ref<boolean>(false);

// Staker info containing registered dApps only.
// Rewards can't be re-staked for unregistered dApps.
const stakerInfoRegisteredDapps =
computed<Map<string, SingularStakingInfo>>(() => {
const result = new Map<string, SingularStakingInfo>();

stakerInfo.value.forEach((value, key) => {
const dapp = getDapp(key);
if (dapp) {
result.set(key, value);
}
});

return result;
});

const amountToClaim = computed<bigint>(() => {
if (props.claimType === ClaimType.Staker) {
return rewards.value.staker.amount;
} else if (props.claimType === ClaimType.Bonus) {
}

if (props.claimType === ClaimType.Bonus) {
return rewards.value.bonus;
} else {
return totalStakerRewards.value;
}

return totalStakerRewards.value;
});

const setShowRestakeModal = async (value: boolean) => {
// Idea is to restake proportionally to already staked dApps.
// At the beginning of a period all stakes are reset so user will be able to claim rewards only.
if (value && stakerInfo.value.size === 0) {
if (value && stakerInfoRegisteredDapps.value.size === 0) {
await handleRestakeConfirm(false);
} else {
showRestakeModal.value = value;
}
};

const handleRestakeConfirm = async (restake: boolean): Promise<void> => {
if (restake && stakerInfo.value.size > 0) {
if (restake && stakerInfoRegisteredDapps.value.size > 0) {
await vote(restake);
} else {
if (props.claimType === ClaimType.Staker) {
Expand Down
2 changes: 1 addition & 1 deletion src/staking-v3/components/my-staking/MyStaking.vue
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ export default defineComponent({
formatPeriod,
} = useDappStaking();

const bonus = ref<BigInt>(BigInt(0));
const bonus = ref<bigint>(BigInt(0));
const { getEstimatedBonus } = useAprV3({ isWatch: false });

const { navigateToVote } = useDappStakingNavigation();
Expand Down
12 changes: 6 additions & 6 deletions src/staking-v3/components/vote/VotingWizard.vue
Original file line number Diff line number Diff line change
Expand Up @@ -74,10 +74,10 @@
<script lang="ts">
import { defineComponent, ref, computed, watch } from 'vue';
import { useI18n } from 'vue-i18n';
import { WizardItem } from './types';
import { DappVote, mapToDappVote } from '../../logic';
import type { WizardItem } from './types';
import { type DappVote, mapToDappVote } from '../../logic';
import { useSelectableComponent, useVote, useDapps, useDappStaking } from 'src/staking-v3/hooks';
import ChooseAmountsPanel, { StakeInfo } from './enter-amount/ChooseAmountsPanel.vue';
import ChooseAmountsPanel, { type StakeInfo } from './enter-amount/ChooseAmountsPanel.vue';
import ReviewPanel from './review/ReviewPanel.vue';
import ChooseDappsPanel from './choose-dapps/ChooseDappsPanel.vue';
import WizardSteps from './WizardSteps.vue';
Expand All @@ -87,9 +87,9 @@ import ModalRestake from './re-stake/ModalRestake.vue';
import { useNetworkInfo } from 'src/hooks';

enum Steps {
ChooseDapps,
AddAmount,
Review,
ChooseDapps = 0,
AddAmount = 1,
Review = 2,
}

export default defineComponent({
Expand Down
12 changes: 6 additions & 6 deletions src/staking-v3/components/vote/choose-dapps/ChooseDappsPanel.vue
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
<div class="main-container">
<dapp-search :title="title" :search-term="searchTerm" :on-search="handleSearch" />
<choose-category
v-if="currentView === View.Category"
v-show="currentView === View.Category"
:on-category-selected="handleCategorySelected"
/>
<dapps-list
v-if="currentView === View.Dapps"
v-show="currentView === View.Dapps"
:dapps="dapps"
:category="currentCategory"
:filter="searchTerm"
Expand All @@ -23,18 +23,18 @@
</div>
</template>
<script lang="ts">
import { defineComponent, computed, ref, PropType } from 'vue';
import { defineComponent, computed, ref, type PropType } from 'vue';
import DappsList from './DappsList.vue';
import ChooseCategory from './ChooseCategory.vue';
import DappSearch from './DappSearch.vue';
import GoBackButton from '../GoBackButton.vue';
import { DappVote, mapToDappVote } from '../../../logic';
import { type DappVote, mapToDappVote } from '../../../logic';
import { useDapps } from 'src/staking-v3/hooks';
import { useI18n } from 'vue-i18n';

enum View {
Category,
Dapps,
Category = 0,
Dapps = 1,
}

export default defineComponent({
Expand Down
2 changes: 1 addition & 1 deletion src/staking-v3/components/vote/choose-dapps/DappSearch.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
</template>

<script lang="ts">
import { defineComponent, PropType } from 'vue';
import { defineComponent, type PropType } from 'vue';

export default defineComponent({
props: {
Expand Down
29 changes: 18 additions & 11 deletions src/staking-v3/components/vote/choose-dapps/DappsList.vue
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,10 @@
</template>

<script lang="ts">
import { defineComponent, PropType, ref, computed } from 'vue';
import { defineComponent, type PropType, ref, computed } from 'vue';
import { useDappStaking } from 'src/staking-v3/hooks';
import DappIcon from '../DappIcon.vue';
import { DappVote } from '../../../logic';
import type { DappVote } from '../../../logic';
import FormatBalance from 'src/components/common/FormatBalance.vue';

// Import Swiper
Expand Down Expand Up @@ -97,13 +97,16 @@ export default defineComponent({
}
if (props.category) {
return props.dapps.filter((dapp) => categoryFilter(dapp, props.category));
} else if (props.filter) {
}

if (props.filter) {
return props.dapps.filter((dapp) =>
dapp.name.toLowerCase().includes(props.filter.toLowerCase())
);
} else {
return props.dapps;
}

return props.dapps;

});

const selectedIndexes = ref<number[]>([]);
Expand All @@ -112,29 +115,33 @@ export default defineComponent({
() => constants.value?.maxNumberOfStakedContracts ?? 0
);

const globalDappIndex = (filteredIndex: number): number =>
props.dapps.findIndex((dapp) => dapp === filteredDapps.value[filteredIndex]);

const handleItemSelected = (index: number): void => {
const indexToRemove = selectedIndexes.value.indexOf(index);
const dappIndex = globalDappIndex(index);
const indexToRemove = selectedIndexes.value.indexOf(dappIndex);
if (indexToRemove >= 0) {
selectedIndexes.value.splice(indexToRemove, 1);
} else {
if (selectedIndexes.value.length <= maxDappsToSelect.value) {
selectedIndexes.value.push(index);
selectedIndexes.value.push(dappIndex);
}
}

if (props.onDappsSelected) {
props.onDappsSelected(
selectedIndexes.value.map((selectedIndex) => filteredDapps.value[selectedIndex])
selectedIndexes.value.map((selectedIndex) => props.dapps[selectedIndex])
);
}
};

const getSelectionOrder = (index: number): number | undefined => {
const number = selectedIndexes.value.indexOf(index) + 1;

const number = selectedIndexes.value.indexOf(globalDappIndex(index)) + 1;
return number === 0 ? undefined : number;
};

const isItemSelected = (index: number): boolean => selectedIndexes.value.includes(index);
const isItemSelected = (index: number): boolean => selectedIndexes.value.includes(globalDappIndex(index));

return {
modules: [Grid, Navigation],
Expand Down
19 changes: 1 addition & 18 deletions src/staking-v3/hooks/useAprV3.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,9 @@
import { u128 } from '@polkadot/types';
import { $api } from 'boot/api';
import { ethers } from 'ethers';
import { container } from 'src/v2/common';
import { IInflationRepository } from 'src/v2/repositories';
import { Symbols } from 'src/v2/symbols';
import { computed, ref, watch } from 'vue';
import { EraInfo, EraLengths, IDappStakingService, InflationParam } from '../logic';
import { IDappStakingService } from '../logic';
import { useDappStaking } from './useDappStaking';
import { weiToToken } from 'src/token-utils';

export const useAprV3 = ({ isWatch }: { isWatch: boolean }) => {
const stakerApr = ref<number>(0);
Expand All @@ -16,19 +12,6 @@ export const useAprV3 = ({ isWatch }: { isWatch: boolean }) => {

const periodsPerCycle = computed<number>(() => eraLengths.value.periodsPerCycle);

const getCyclePerYear = (eraLength: EraLengths): number => {
const secBlockProductionRate = 12;
const secsOneYear = 365 * 24 * 60 * 60;
const periodLength =
eraLength.standardErasPerBuildAndEarnPeriod + eraLength.standardErasPerVotingPeriod;

const eraPerCycle = periodLength * periodsPerCycle.value;
const blocksStandardEraLength = eraLength.standardEraLength;
const blockPerCycle = blocksStandardEraLength * eraPerCycle;
const cyclePerYear = secsOneYear / secBlockProductionRate / blockPerCycle;
return cyclePerYear;
};

const getApr = async (): Promise<{ stakerApr: number; bonusApr: number }> => {
try {
const stakingService = container.get<IDappStakingService>(Symbols.DappStakingServiceV3);
Expand Down
8 changes: 4 additions & 4 deletions src/staking-v3/hooks/useDappStaking.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ export function useDappStaking() {
);
const staker = await stakingService.getStakerRewards(currentAccount.value);
const bonus = await stakingService.getBonusRewards(currentAccount.value);
store.commit('stakingV3/setRewards', { ...rewards.value, staker, bonus });
store.commit('stakingV3/setRewards', { ...rewards.value, staker, bonus: bonus.amount });
getCurrentEraInfo();
fetchStakeAmountsToStore();
await fetchStakerInfoToStore();
Expand All @@ -214,7 +214,7 @@ export function useDappStaking() {
stakingService.getBonusRewards(currentAccount.value),
stakingService.getDappRewards(dappAddress),
]);
store.commit('stakingV3/setRewards', { ...rewards.value, staker, bonus, dApp });
store.commit('stakingV3/setRewards', { ...rewards.value, staker, bonus: bonus.amount, dApp });
fetchStakerInfoToStore();
getCurrentEraInfo();
fetchStakeAmountsToStore();
Expand Down Expand Up @@ -272,7 +272,7 @@ export function useDappStaking() {
t('stakingV3.claimBonusRewardSuccess')
);
const bonus = await stakingService.getBonusRewards(currentAccount.value);
store.commit('stakingV3/setRewards', { ...rewards.value, bonus });
store.commit('stakingV3/setRewards', { ...rewards.value, bonus: bonus.amount });
};

const claimDappRewards = async (contractAddress: string): Promise<void> => {
Expand Down Expand Up @@ -303,7 +303,7 @@ export function useDappStaking() {
);
const staker = await stakingService.getStakerRewards(currentAccount.value);
const bonus = await stakingService.getBonusRewards(currentAccount.value);
store.commit('stakingV3/setRewards', { ...rewards.value, staker, bonus });
store.commit('stakingV3/setRewards', { ...rewards.value, staker, bonus: bonus.amount });
};

const withdraw = async (): Promise<void> => {
Expand Down
2 changes: 1 addition & 1 deletion src/staking-v3/hooks/useVote.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { Ref, computed, ref, watch } from 'vue';
import { CombinedDappInfo, DappStakeInfo, DappVote } from '../logic';
import type { CombinedDappInfo, DappStakeInfo, DappVote } from '../logic';
import { ethers } from 'ethers';
import { useAccount, useBalance } from 'src/hooks';
import { useDappStaking } from './useDappStaking';
Expand Down
6 changes: 4 additions & 2 deletions src/staking-v3/hooks/useVotingCountdown.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
import { computed } from 'vue';
import { useDappStaking } from './useDappStaking';
import { PeriodType } from '../logic';
import { useBlockTime } from 'src/hooks';

export function useVotingCountdown() {
const { protocolState, currentBlock } = useDappStaking();
const blockTimeInSeconds = 12;
const { blockTimeInSeconds } = useBlockTime();

const secondsLeft = computed<number>(() => {
if (
protocolState.value === undefined ||
currentBlock.value === undefined ||
blockTimeInSeconds.value === undefined ||
protocolState.value.periodInfo.subperiod === PeriodType.BuildAndEarn
) {
return 0;
}

return (protocolState.value.nextEraStart - currentBlock.value) * blockTimeInSeconds;
return (protocolState.value.nextEraStart - currentBlock.value) * blockTimeInSeconds.value;
});

const timeLeftFormatted = computed<string>(() => {
Expand Down
Loading
Loading