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

dApp staking v3 #1023

Merged
merged 77 commits into from
Jan 8, 2024
Merged
Show file tree
Hide file tree
Changes from 68 commits
Commits
Show all changes
77 commits
Select commit Hold shift + click to select a range
2faa522
Defined v3 project structure
bobo-k2 Oct 10, 2023
05ca294
Stake, unstake skeletons
bobo-k2 Oct 10, 2023
3165911
Code organization improvements
bobo-k2 Oct 12, 2023
bd72bd2
Get protocol state
bobo-k2 Oct 30, 2023
c97a82c
Protocol change notification message
bobo-k2 Oct 31, 2023
cf82b2c
Merge branch 'main' into feat/dapp-staking-v3
bobo-k2 Oct 31, 2023
602f2bb
Lock and stake
bobo-k2 Oct 31, 2023
8be2738
Read account ledger
bobo-k2 Oct 31, 2023
80f9cea
Unstake call
bobo-k2 Nov 2, 2023
69fd2c1
unstake and unlock, claim staker
bobo-k2 Nov 3, 2023
02e3569
Staker info
bobo-k2 Nov 3, 2023
cd96a18
Started with can stake logic
bobo-k2 Nov 3, 2023
981a64d
Updated node types
bobo-k2 Nov 8, 2023
d79acdc
Staker reward calculation part 1
bobo-k2 Nov 10, 2023
eccface
Staker rewards calculation part 2
bobo-k2 Nov 11, 2023
2eeb12d
dApp rewards calculation and claim
bobo-k2 Nov 13, 2023
4300015
Calculate and claim bonus rewards
bobo-k2 Nov 13, 2023
dafbeef
Merge branch 'main' of github.com-impelcrypto:AstarNetwork/astar-apps…
impelcrypto Nov 14, 2023
f9e37cf
Calculate claim staker batch size fix
bobo-k2 Nov 14, 2023
c484606
Merge branch 'feat/dapp-staking-v3' of github.com:AstarNetwork/astar-…
bobo-k2 Nov 14, 2023
39f2723
Rewards fetch fix
bobo-k2 Nov 15, 2023
92b2575
can claim methods
bobo-k2 Nov 15, 2023
2d10a35
Can Claim bug fix
bobo-k2 Nov 15, 2023
6a5cbb9
fix: conflicts
impelcrypto Nov 16, 2023
08a4123
feat: Prevents Errors from Occuring (#1026)
gluneau Nov 16, 2023
879705a
feat: added top page (#1033)
impelcrypto Nov 20, 2023
1d72212
Vote mobile page and logic (#1036)
bobo-k2 Nov 20, 2023
d138309
Vote batch bug fixes
bobo-k2 Nov 20, 2023
bd3d882
vote and dictionary changes (#1037)
gluneau Nov 21, 2023
493e7a2
Vote on multiple dApps (#1046)
bobo-k2 Nov 23, 2023
e5a82f4
feat: link to the project page (#1049)
impelcrypto Nov 24, 2023
fafa2bd
styles: added 'current tier' and 'total earned' (#1053)
impelcrypto Nov 28, 2023
e3be666
pulled latest main branch (#1057)
impelcrypto Nov 29, 2023
988912e
Staking panels and leaderboard (#1056)
bobo-k2 Nov 29, 2023
b529b3a
feat: added owner section on the assets page (#1059)
impelcrypto Nov 30, 2023
809538f
Staking v3 data (#1064)
bobo-k2 Dec 1, 2023
364c344
Compatibility issues fix (#1075)
bobo-k2 Dec 5, 2023
246f020
feat: maxUnlockingChunks (#1071)
gluneau Dec 5, 2023
d66ada2
Merge branch 'main' into feat/dapp-staking-v3
bobo-k2 Dec 7, 2023
0310cc2
Remove commented
bobo-k2 Dec 7, 2023
6b3337e
feat: added owner section (#1079)
impelcrypto Dec 7, 2023
0cd3444
fix: copy the project page components to the staking-v3 folder (#1085)
impelcrypto Dec 11, 2023
3608a6a
Owner page logic and unstake from unregistered (#1088)
bobo-k2 Dec 12, 2023
ade332b
Feat/staking v3 improvements4 (#1089)
bobo-k2 Dec 14, 2023
727639b
Merge branch 'main' into feat/dapp-staking-v3
bobo-k2 Dec 20, 2023
caaaf72
Add Shibuya Scope Style (#1078)
ayumitk Dec 20, 2023
30743f4
Show success messages and tier rewards (#1097)
bobo-k2 Dec 21, 2023
3899ceb
dApp search bug fix, amount to be locked fix
bobo-k2 Dec 21, 2023
783d75d
Build error fix
bobo-k2 Dec 21, 2023
a0a4f7b
Nomination transfer
bobo-k2 Dec 22, 2023
e90bcd0
Disable Vote button if no stakes.
bobo-k2 Dec 22, 2023
af705b2
Reward calculation fix, unlock
bobo-k2 Dec 27, 2023
ae8db28
v3 vote period style (#1098)
ayumitk Dec 28, 2023
75cb4ad
Show nomination transfer info on Voting page
bobo-k2 Dec 28, 2023
dc84ab8
Merge branch 'main' into feat/dapp-staking-v3
bobo-k2 Dec 29, 2023
0141319
feat: added EVM supports (#1102)
impelcrypto Dec 29, 2023
ff40d60
EVM unlock fix
bobo-k2 Dec 29, 2023
43a3b32
fix: added todo comment
impelcrypto Dec 29, 2023
60f1f95
GetTier bug fix and removed some comments
bobo-k2 Dec 29, 2023
51ef615
Merge branch 'feat/dapp-staking-v3' of github.com:AstarNetwork/astar-…
bobo-k2 Dec 29, 2023
13f5be1
fix: removed unused files
impelcrypto Dec 29, 2023
ab5fa57
Comments cleanup
bobo-k2 Dec 29, 2023
e36c1f2
Merge branch 'feat/dapp-staking-v3' of github.com:AstarNetwork/astar-…
bobo-k2 Dec 29, 2023
fa15821
Gas price provider fix
bobo-k2 Dec 29, 2023
71b7f60
Message subscriptions, check value before assignment.
bobo-k2 Dec 29, 2023
9f15773
Nomination transfer bug fix, styling and translations
bobo-k2 Dec 29, 2023
8721679
Nomination transfer amount, total stake
bobo-k2 Jan 3, 2024
c82e7ab
Leaderboard fix, multiplier removed
bobo-k2 Jan 3, 2024
db8e201
Staker reward calculation optimisation
bobo-k2 Jan 4, 2024
c242ae2
Merge branch 'main' into feat/dapp-staking-v3
bobo-k2 Jan 4, 2024
3a7af62
Clam banner text update for Shibuya
bobo-k2 Jan 4, 2024
de005f5
Voting period countdown
bobo-k2 Jan 4, 2024
9576d94
Current period day and canConfirm fixes
bobo-k2 Jan 5, 2024
ea3f67b
feat: update project page styles (#1109)
ayumitk Jan 8, 2024
79306d9
feat: add migrate support style (#1114)
ayumitk Jan 8, 2024
535b58f
Hide migration support for now
bobo-k2 Jan 8, 2024
2e6263e
feat: added staker and bonus rewards APR (#1113)
impelcrypto Jan 8, 2024
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
1 change: 1 addition & 0 deletions .eslintignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@
.eslintrc.js
babel.config.js
/src-ssr
/src-pwa
/tests/polkadot_wallet
/tests/metamask_wallet
5 changes: 4 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,8 @@ zombienet-macos
polkadot
astar-collator

# Temp folder
*temp

# Chopstick binaries
db.sqlite*
db.sqlite*
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
},
"dependencies": {
"@astar-network/astar-sdk-core": "^0.2.8",
"@astar-network/astar-ui": "^0.0.136",
"@astar-network/astar-ui": "^0.0.137",
"@astar-network/metamask-astar-adapter": "^0.5.4",
"@astar-network/metamask-astar-types": "^0.6.1",
"@ethersproject/bignumber": "^5.5.0",
Expand Down
82 changes: 78 additions & 4 deletions src/App.vue
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@
// https://polkadot.js.org/docs/api/FAQ/#since-upgrading-to-the-7x-series-typescript-augmentation-is-missing
import 'reflect-metadata';
import '@polkadot/api-augment';
import { defineComponent, computed, ref, watch } from 'vue';
import { defineComponent, computed, ref, watch, onMounted } from 'vue';
import DashboardLayout from 'layouts/DashboardLayout.vue';
import { useStore } from 'src/store';
import ModalLoading from 'components/common/ModalLoading.vue';
Expand All @@ -61,6 +61,13 @@ import { container } from 'src/v2/common';
import { Symbols } from 'src/v2/symbols';
import { useAccount, useAppRouter } from 'src/hooks';
import { LOCAL_STORAGE } from 'src/config/localStorage';
import {
AccountLedgerChangedMessage,
IDappStakingService,
ProtocolStateChangedMessage,
} from './staking-v3';
import { useDappStaking, useDapps } from './staking-v3/hooks';
import { IDappStakingRepository as IDappStakingRepositoryV3 } from 'src/staking-v3/logic/repositories';

export default defineComponent({
name: 'App',
Expand All @@ -75,7 +82,18 @@ export default defineComponent({
setup() {
useAppRouter();
const store = useStore();
const { currentAccountName } = useAccount();
const { currentAccountName, currentAccount } = useAccount();
const {
protocolState,
getAllRewards,
getCurrentEraInfo,
getDappTiers,
fetchStakerInfoToStore,
fetchTiersConfigurationToStore,
fetchEraLengthsToStore,
isDappStakingV3,
} = useDappStaking();
const { fetchStakeAmountsToStore, fetchDappsToStore } = useDapps();

const isLoading = computed(() => store.getters['general/isLoading']);
const showAlert = computed(() => store.getters['general/showAlert']);
Expand All @@ -94,7 +112,7 @@ export default defineComponent({
showDisclaimerModal.value = isOpen;
};

// Handle busy and extrisnsic call status messages.
// Handle busy and extrinsic call status messages.
const eventAggregator = container.get<IEventAggregator>(Symbols.EventAggregator);
eventAggregator.subscribe(ExtrinsicStatusMessage.name, (m) => {
const message = m as ExtrinsicStatusMessage;
Expand Down Expand Up @@ -124,9 +142,65 @@ export default defineComponent({
store.commit('dapps/setCurrentEra', message.era, { root: true });
});

// **** dApp staking v3
// dApp staking v3 data changed subscriptions.
onMounted(() => {
if (isDappStakingV3.value) {
container
.get<IDappStakingRepositoryV3>(Symbols.DappStakingRepositoryV3)
.startProtocolStateSubscription();
}
});

eventAggregator.subscribe(ProtocolStateChangedMessage.name, async (m) => {
const message = m as ProtocolStateChangedMessage;

if (message.state) {
console.log('protocol state', message.state);
store.commit('stakingV3/setProtocolState', message.state, { root: true });
await fetchDappsToStore();
await Promise.all([
getAllRewards(),
getCurrentEraInfo(),
getDappTiers(message.state.era - 1),
fetchStakeAmountsToStore(),
fetchStakerInfoToStore(),
fetchEraLengthsToStore(),
]);
}
});

eventAggregator.subscribe(AccountLedgerChangedMessage.name, (m) => {
const message = m as AccountLedgerChangedMessage;
if (message.ledger) {
store.commit('stakingV3/setLedger', message.ledger, { root: true });
console.log('ledger', message.ledger);
}
});
// **** end dApp staking v3

// Handle wallet change so we can inject proper wallet
watch([isEthWallet, currentWallet, isH160, currentAccountName], () => {
let previousAddress: string | undefined = undefined;
watch([isEthWallet, currentWallet, isH160, currentAccountName], async () => {
setCurrentWallet(isEthWallet.value, currentWallet.value);

// Subscribe to an account specific dApp staking v3 data.
if (!isDappStakingV3.value) return;

// Memo: Can't use senderSs58Account here because unified account is not stored to vuex yet
// and senderSs58Account contains evm mapped address which is incorrect for unified account.
if (currentAccount.value && currentAccount.value !== previousAddress) {
const stakingService = container.get<() => IDappStakingService>(
Symbols.DappStakingServiceFactoryV3
)();
await stakingService.startAccountLedgerSubscription(currentAccount.value);
fetchStakerInfoToStore();
getAllRewards();
fetchTiersConfigurationToStore();
getDappTiers((protocolState.value?.era ?? 0) - 1);

previousAddress = currentAccount.value;
}
});

const removeSplashScreen = () => {
Expand Down
19 changes: 17 additions & 2 deletions src/components/assets/Assets.vue
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,13 @@
:is-loading-xcm-assets-amount="isLoadingXcmAssetsAmount"
/>

<template v-if="isDappStakingV3">
<your-project />
</template>
<template v-if="isDappStakingV3">
<staking />
</template>

<div v-if="!isLoading" class="container">
<div v-if="isH160">
<evm-asset-list :tokens="evmAssets.assets" />
Expand All @@ -30,19 +37,22 @@
</div>
</template>
<script lang="ts">
import { isValidEvmAddress } from '@astar-network/astar-sdk-core';
import Account from 'src/components/assets/Account.vue';
import SideAds from 'src/components/assets/SideAds.vue';
import AstarDomains from 'src/components/header/mobile/AstarDomains.vue';
import EvmAssetList from 'src/components/assets/EvmAssetList.vue';
import XcmNativeAssetList from 'src/components/assets/XcmNativeAssetList.vue';
import YourProject from 'src/components/assets/YourProject.vue';
import { providerEndpoints } from 'src/config/chainEndpoints';
import { LOCAL_STORAGE } from 'src/config/localStorage';
import { isValidEvmAddress } from '@astar-network/astar-sdk-core';
import { useAccount, useBalance, useDispatchGetDapps, useNetworkInfo } from 'src/hooks';
import { useDappStaking } from 'src/staking-v3';
import { useStore } from 'src/store';
import { EvmAssets, XcmAssets, XvmAssets } from 'src/store/assets/state';
import { Asset } from 'src/v2/models';
import { computed, defineComponent, ref, watch, watchEffect, onUnmounted } from 'vue';
import { computed, defineComponent, onUnmounted, ref, watch, watchEffect } from 'vue';
import Staking from 'src/staking-v3/components/my-staking/Staking.vue';

export default defineComponent({
components: {
Expand All @@ -51,14 +61,18 @@ export default defineComponent({
AstarDomains,
EvmAssetList,
XcmNativeAssetList,
YourProject,
Staking,
},
setup() {
const token = ref<Asset | null>(null);
const isModalXcmBridge = ref<boolean>(false);
const isModalXcmTransfer = ref<boolean>(false);
const { isDappStakingV3 } = useDappStaking();

const store = useStore();
const { currentAccount } = useAccount();

const { accountData } = useBalance(currentAccount);
const { isMainnet, currentNetworkIdx, evmNetworkIdx, isZkEvm } = useNetworkInfo();
// Memo: load the dApps data in advance, so that users can access to dApp staging page smoothly
Expand Down Expand Up @@ -184,6 +198,7 @@ export default defineComponent({
isModalXcmBridge,
isLoading,
bg,
isDappStakingV3,
};
},
});
Expand Down
9 changes: 4 additions & 5 deletions src/components/assets/Erc20Currency.vue
Original file line number Diff line number Diff line change
Expand Up @@ -136,20 +136,19 @@
</div>
</template>
<script lang="ts">
import TokenBalance from 'src/components/common/TokenBalance.vue';
import { LOCAL_STORAGE } from 'src/config/localStorage';
import { SupportWallet } from 'src/config/wallets';
import { useNetworkInfo, useBreakpoints } from 'src/hooks';
import { useBreakpoints, useNetworkInfo } from 'src/hooks';
import { addToEvmProvider, getEvmProvider } from 'src/hooks/helper/wallet';
import {
deleteImportedErc20Token,
Erc20Token,
deleteImportedErc20Token,
getErc20Explorer,
getStoredERC20Tokens,
} from 'src/modules/token';
import { buildTransferPageLink, buildEthereumBridgePageLink } from 'src/router/routes';
import { buildEthereumBridgePageLink, buildTransferPageLink } from 'src/router/routes';
import { useStore } from 'src/store';
import { computed, defineComponent, PropType, ref } from 'vue';
import { PropType, computed, defineComponent, ref } from 'vue';
import Jazzicon from 'vue3-jazzicon/src/components';
import { truncate } from '@astar-network/astar-sdk-core';

Expand Down
26 changes: 12 additions & 14 deletions src/components/assets/Rewards.vue
Original file line number Diff line number Diff line change
@@ -1,21 +1,19 @@
<template>
<div>
<button v-if="!isDappDeveloper" class="wrapper--rewards" @click="handleClaim">
<div class="container--rewards">
<div class="text--title">
{{ $t('assets.yourEstimatedRewards') }}
</div>
<div class="row--data">
<div class="value">
<div>
<span class="text--amount">{{ $n(pendingRewards || 0) }}</span>
<span class="text--symbol">{{ nativeTokenSymbol }}</span>
</div>
<button v-if="!isDappDeveloper" class="wrapper--rewards" @click="handleClaim">
<div class="container--rewards">
<div class="text--title">
{{ $t('assets.yourEstimatedRewards') }}
</div>
<div class="row--data">
<div class="value">
<div>
<span class="text--amount">{{ $n(pendingRewards || 0) }}</span>
<span class="text--symbol">{{ nativeTokenSymbol }}</span>
</div>
</div>
</div>
</button>
</div>
</div>
</button>
</template>

<script lang="ts">
Expand Down
49 changes: 49 additions & 0 deletions src/components/assets/YourProject.vue
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<template>
<div v-if="ownDapps.length > 0" class="container">
<div class="wrapper--your-project">
<div class="row--title">
<astar-icon-project />
<span class="text--title">{{ $t('assets.yourProject') }}</span>
</div>
<div class="separator" />
<div class="box--dapps">
<router-link
v-for="dapp in ownDapps"
:key="dapp.basic.address"
:to="navigateOwnerPage(dapp.basic.address)"
class="card--dapp"
>
<img class="icon--dapp-logo" :src="dapp.basic.iconUrl" :alt="dapp.basic.name" />
<div>
<span>{{ dapp.basic.name }}</span>
</div>
</router-link>
</div>
</div>
</div>
</template>

<script lang="ts">
import { useAccount, useClaimAll } from 'src/hooks';
import { CombinedDappInfo, useDappStakingNavigation, useDapps } from 'src/staking-v3';
import { computed, defineComponent } from 'vue';

export default defineComponent({
setup() {
const { currentAccount } = useAccount();
useClaimAll();
const { allDapps } = useDapps();
const { navigateOwnerPage } = useDappStakingNavigation();
const ownDapps = computed<CombinedDappInfo[]>(() => {
if (!allDapps.value) return [];
return allDapps.value.filter((dapp) => dapp.chain.owner === currentAccount.value);
});

return { ownDapps, navigateOwnerPage };
},
});
</script>

<style lang="scss" scoped>
@use 'src/components/assets/styles/your-project.scss';
</style>
Loading
Loading