Skip to content

Commit

Permalink
WebRunner for TAO inappp-staking feature
Browse files Browse the repository at this point in the history
  • Loading branch information
dominhquang committed Oct 15, 2024
1 parent 2c00906 commit 0f2bf25
Show file tree
Hide file tree
Showing 20 changed files with 572 additions and 13 deletions.
2 changes: 2 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -3,3 +3,5 @@ COINBASE_PAY_ID=1dbd2a0b94
NFT_MINTING_HOST=http://...
CHAINFLIP_BROKER_API=93c2bff017e243f29ffb14e42dccbec8
BRANCH_NAME=master
BITTENSOR_API_KEY_1=abavbav
BITTENSOR_API_KEY_2=abafdbad
2 changes: 2 additions & 0 deletions .github/workflows/push-koni-dev.yml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ jobs:
TRANSAK_API_KEY: ${{ secrets.TRANSAK_API_KEY }}
COINBASE_PAY_ID: ${{ secrets.COINBASE_PAY_ID }}
CHAINFLIP_BROKER_API: ${{ secrets.CHAINFLIP_BROKER_API }}
BITTENSOR_API_KEY_1: ${{ secrets.BITTENSOR_API_KEY_1 }}
BITTENSOR_API_KEY_2: ${{ secrets.BITTENSOR_API_KEY_2 }}
GH_RELEASE_FILES: master-build.zip,master-src.zip
COMMIT_MESSAGE: ${{ github.event.head_commit.message }}
REF_NAME: ${{ github.ref_name }}
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/push-master.yml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ jobs:
TRANSAK_API_KEY: ${{ secrets.TRANSAK_API_KEY }}
COINBASE_PAY_ID: ${{ secrets.COINBASE_PAY_ID }}
CHAINFLIP_BROKER_API: ${{ secrets.CHAINFLIP_BROKER_API }}
BITTENSOR_API_KEY_1: ${{ secrets.BITTENSOR_API_KEY_1 }}
BITTENSOR_API_KEY_2: ${{ secrets.BITTENSOR_API_KEY_2 }}
BRANCH_NAME: ${{ github.ref_name }}
run: |
yarn install --immutable | grep -v 'YN0013'
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/push-web-runner.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ jobs:
TRANSAK_API_KEY: ${{ secrets.TRANSAK_API_KEY }}
COINBASE_PAY_ID: ${{ secrets.COINBASE_PAY_ID }}
CHAINFLIP_BROKER_API: ${{ secrets.CHAINFLIP_BROKER_API }}
BITTENSOR_API_KEY_1: ${{ secrets.BITTENSOR_API_KEY_1 }}
BITTENSOR_API_KEY_2: ${{ secrets.BITTENSOR_API_KEY_2 }}
BRANCH_NAME: master
run: |
yarn install --immutable | grep -v 'YN0013'
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/push-webapp.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ jobs:
COINBASE_PAY_ID: ${{ secrets.COINBASE_PAY_ID }}
NFT_MINTING_HOST: ${{ secrets.NFT_MINTING_HOST }}
CHAINFLIP_BROKER_API: ${{ secrets.CHAINFLIP_BROKER_API }}
BITTENSOR_API_KEY_1: ${{ secrets.BITTENSOR_API_KEY_1 }}
BITTENSOR_API_KEY_2: ${{ secrets.BITTENSOR_API_KEY_2 }}
BRANCH_NAME: ${{ github.ref_name }}
run: |
yarn install --immutable | grep -v 'YN0013'
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@
"@polkadot/types-support": "^12.0.2",
"@polkadot/util": "^12.6.2",
"@polkadot/util-crypto": "^12.6.2",
"@subwallet/chain-list": "0.2.88",
"@subwallet/chain-list": "0.2.88-beta.6",
"@subwallet/keyring": "^0.1.7",
"@subwallet/react-ui": "5.1.2-b79",
"@subwallet/ui-keyring": "^0.1.7",
Expand Down
2 changes: 2 additions & 0 deletions packages/extension-base/src/constants/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@ export const CRON_REFRESH_CHAIN_NOMINATOR_METADATA = 1800000;
export const CRON_RECOVER_HISTORY_INTERVAL = 30000;
export const CRON_SYNC_MANTA_PAY = 300000;
export const MANTA_PAY_BALANCE_INTERVAL = 30000;
export const BITTENSOR_REFRESH_STAKE_INFO = 30000;
export const BITTENSOR_REFRESH_STAKE_APY = 300000;
export const CRON_REFRESH_EARNING_REWARD_HISTORY_INTERVAL = 15 * BASE_MINUTE_INTERVAL;

export const ALL_ACCOUNT_KEY = 'ALL';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -541,7 +541,7 @@ export function getEarningStatusByNominations (bnTotalActiveStake: BN, nominatio
export function getValidatorLabel (chain: string) {
if (_STAKING_CHAIN_GROUP.astar.includes(chain)) {
return 'dApp';
} else if (_STAKING_CHAIN_GROUP.relay.includes(chain)) {
} else if (_STAKING_CHAIN_GROUP.relay.includes(chain) || _STAKING_CHAIN_GROUP.bittensor.includes(chain)) {
return 'Validator';
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ import { getDefaultWeightV2 } from '@subwallet/extension-base/koni/api/contract-
import { _BALANCE_CHAIN_GROUP, _MANTA_ZK_CHAIN_GROUP, _ZK_ASSET_PREFIX } from '@subwallet/extension-base/services/chain-service/constants';
import { _EvmApi, _SubstrateAdapterSubscriptionArgs, _SubstrateApi } from '@subwallet/extension-base/services/chain-service/types';
import { _checkSmartContractSupportByChain, _getAssetExistentialDeposit, _getChainExistentialDeposit, _getChainNativeTokenSlug, _getContractAddressOfToken, _getTokenOnChainAssetId, _getTokenOnChainInfo, _getTokenTypesSupportedByChain, _getXcmAssetMultilocation, _isBridgedToken, _isChainEvmCompatible } from '@subwallet/extension-base/services/chain-service/utils';
import { fetchTaoDelegateState } from '@subwallet/extension-base/services/earning-service/handlers/native-staking/tao';
import { getTaoTotalStake } from '@subwallet/extension-base/services/earning-service/utils';
import { BalanceItem, SubscribeBasePalletBalance, SubscribeSubstratePalletBalance } from '@subwallet/extension-base/types';
import { filterAssetsByChainAndType } from '@subwallet/extension-base/utils';
import BigN from 'bignumber.js';
Expand Down Expand Up @@ -142,6 +144,16 @@ const subscribeWithSystemAccountPallet = async ({ addresses, callback, chainInfo
);
}

let bittensorStakingBalances = new Array<bigint>(addresses.length).fill(BigInt(0));

if (['bittensor'].includes(chainInfo.slug)) {
bittensorStakingBalances = await Promise.all(addresses.map(async (address) => {
const rawDelegateState = await fetchTaoDelegateState(address);

return getTaoTotalStake(rawDelegateState);
}));
}

const subscription = substrateApi.subscribeDataWithMulti(params, (rs) => {
const balances = rs[systemAccountKey];
const poolMemberInfos = rs[poolMembersKey];
Expand All @@ -161,6 +173,8 @@ const subscribeWithSystemAccountPallet = async ({ addresses, callback, chainInfo
totalLockedFromTransfer += nominationPoolBalance;
}

totalLockedFromTransfer += bittensorStakingBalances[index];

return ({
address: addresses[index],
tokenSlug: _getChainNativeTokenSlug(chainInfo),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,8 @@ export const _STAKING_CHAIN_GROUP = {
liquidStaking: ['bifrost_dot', 'acala', 'parallel', 'moonbeam'],
lending: ['interlay'],
krest_network: ['krest_network'],
manta: ['manta_network']
manta: ['manta_network'],
bittensor: ['bittensor', 'bittensor_devnet']
};

export const MaxEraRewardPointsEras = 14;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ export { default as AmplitudeNativeStakingPoolHandler } from './amplitude';
export { default as AstarNativeStakingPoolHandler } from './astar';
export { default as RelayNativeStakingPoolHandler } from './relay-chain';
export { default as ParaNativeStakingPoolHandler } from './para-chain';
export { default as TaoNativeStakingPoolHandler } from './tao';
Loading

1 comment on commit 0f2bf25

@saltict
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.