From a2a3ced286ce6b3a17891e59a9a401953a0a1019 Mon Sep 17 00:00:00 2001 From: tunghp2002 Date: Thu, 17 Oct 2024 17:36:02 +0700 Subject: [PATCH 1/4] [Update] Migrate STAKING_JOIN_POOL --- .../extension-base/src/background/KoniTypes.ts | 2 +- .../src/koni/api/yield/helper/utils.ts | 2 +- .../handlers/nomination-pool/index.ts | 16 +++++++--------- .../Confirmations/variants/Transaction/index.tsx | 2 +- .../variants/Transaction/variants/JoinPool.tsx | 15 ++++++++------- .../src/messaging/transaction/staking.ts | 6 +++--- 6 files changed, 21 insertions(+), 22 deletions(-) diff --git a/packages/extension-base/src/background/KoniTypes.ts b/packages/extension-base/src/background/KoniTypes.ts index 890205b5de..fe4e77d3cc 100644 --- a/packages/extension-base/src/background/KoniTypes.ts +++ b/packages/extension-base/src/background/KoniTypes.ts @@ -1887,7 +1887,7 @@ export interface KoniRequestSignatures { 'pri(bonding.subscribeNominatorMetadata)': [null, NominatorMetadata[], NominatorMetadata[]]; 'pri(bonding.getBondingOptions)': [BondingOptionParams, ValidatorInfo[]]; 'pri(bonding.getNominationPoolOptions)': [string, NominationPoolInfo[]]; - 'pri(bonding.nominationPool.submitBonding)': [RequestStakePoolingBonding, SWTransactionResponse]; + 'pri(bonding.nominationPool.submitBonding)': [RequestYieldStepSubmit, SWTransactionResponse]; 'pri(bonding.nominationPool.submitUnbonding)': [RequestStakePoolingUnbonding, SWTransactionResponse]; // Chains, assets functions diff --git a/packages/extension-base/src/koni/api/yield/helper/utils.ts b/packages/extension-base/src/koni/api/yield/helper/utils.ts index 52120f110d..f08513fd46 100644 --- a/packages/extension-base/src/koni/api/yield/helper/utils.ts +++ b/packages/extension-base/src/koni/api/yield/helper/utils.ts @@ -19,7 +19,7 @@ export const YIELD_EXTRINSIC_TYPES = [ ExtrinsicType.REDEEM_VDOT, ExtrinsicType.REDEEM_LDOT, ExtrinsicType.REDEEM_STDOT, - ExtrinsicType.STAKING_JOIN_POOL, + ExtrinsicType.JOIN_YIELD_POOL, ExtrinsicType.STAKING_CLAIM_REWARD, ExtrinsicType.STAKING_LEAVE_POOL, ExtrinsicType.STAKING_POOL_WITHDRAW diff --git a/packages/extension-base/src/services/earning-service/handlers/nomination-pool/index.ts b/packages/extension-base/src/services/earning-service/handlers/nomination-pool/index.ts index 096606c1f1..156eeaa72c 100644 --- a/packages/extension-base/src/services/earning-service/handlers/nomination-pool/index.ts +++ b/packages/extension-base/src/services/earning-service/handlers/nomination-pool/index.ts @@ -9,7 +9,7 @@ import KoniState from '@subwallet/extension-base/koni/background/handlers/State' import { _STAKING_ERA_LENGTH_MAP } from '@subwallet/extension-base/services/chain-service/constants'; import { _SubstrateApi } from '@subwallet/extension-base/services/chain-service/types'; import { _getChainSubstrateAddressPrefix } from '@subwallet/extension-base/services/chain-service/utils'; -import { BaseYieldPositionInfo, BasicTxErrorType, EarningRewardHistoryItem, EarningRewardItem, EarningStatus, HandleYieldStepData, NominationPoolInfo, NominationYieldPoolInfo, OptimalYieldPath, OptimalYieldPathParams, PalletNominationPoolsBondedPoolInner, PalletStakingActiveEraInfo, PalletStakingExposure, PalletStakingExposureItem, PalletStakingNominations, RequestStakePoolingBonding, SpStakingExposurePage, StakeCancelWithdrawalParams, StakingTxErrorType, SubmitJoinNominationPool, SubmitYieldJoinData, TransactionData, UnstakingStatus, YieldPoolInfo, YieldPoolMethodInfo, YieldPoolType, YieldPositionInfo, YieldStepBaseInfo, YieldStepType, YieldTokenBaseInfo } from '@subwallet/extension-base/types'; +import { BaseYieldPositionInfo, BasicTxErrorType, EarningRewardHistoryItem, EarningRewardItem, EarningStatus, HandleYieldStepData, NominationPoolInfo, NominationYieldPoolInfo, OptimalYieldPath, OptimalYieldPathParams, PalletNominationPoolsBondedPoolInner, PalletStakingActiveEraInfo, PalletStakingExposure, PalletStakingExposureItem, PalletStakingNominations, RequestYieldStepSubmit, SpStakingExposurePage, StakeCancelWithdrawalParams, StakingTxErrorType, SubmitJoinNominationPool, SubmitYieldJoinData, TransactionData, UnstakingStatus, YieldPoolInfo, YieldPoolMethodInfo, YieldPoolType, YieldPositionInfo, YieldStepBaseInfo, YieldStepType, YieldTokenBaseInfo } from '@subwallet/extension-base/types'; import { balanceFormatter, formatNumber, reformatAddress } from '@subwallet/extension-base/utils'; import BigN from 'bignumber.js'; import { t } from 'i18next'; @@ -569,21 +569,19 @@ export default class NominationPoolHandler extends BasePoolHandler { async handleYieldJoin (_data: SubmitYieldJoinData, path: OptimalYieldPath, currentStep: number): Promise { const data = _data as SubmitJoinNominationPool; - const { address, amount, selectedPool } = data; + const { address, amount } = data; const positionInfo = await this.getPoolPosition(address); const [extrinsic] = await this.createJoinExtrinsic(data, positionInfo); - const joinPoolData: RequestStakePoolingBonding = { - poolPosition: positionInfo, - slug: this.slug, - selectedPool, - amount, - address + const joinPoolData: RequestYieldStepSubmit = { + path, + data: data, + currentStep }; return { txChain: this.chain, - extrinsicType: ExtrinsicType.STAKING_JOIN_POOL, + extrinsicType: ExtrinsicType.JOIN_YIELD_POOL, extrinsic, txData: joinPoolData, transferNativeAmount: amount, diff --git a/packages/extension-koni-ui/src/Popup/Confirmations/variants/Transaction/index.tsx b/packages/extension-koni-ui/src/Popup/Confirmations/variants/Transaction/index.tsx index bf91f3e4d9..c175867453 100644 --- a/packages/extension-koni-ui/src/Popup/Confirmations/variants/Transaction/index.tsx +++ b/packages/extension-koni-ui/src/Popup/Confirmations/variants/Transaction/index.tsx @@ -34,11 +34,11 @@ const getTransactionComponent = (extrinsicType: ExtrinsicType): typeof BaseTrans case ExtrinsicType.SEND_NFT: return SendNftTransactionConfirmation; case ExtrinsicType.STAKING_JOIN_POOL: + case ExtrinsicType.JOIN_YIELD_POOL: return JoinPoolTransactionConfirmation; case ExtrinsicType.STAKING_LEAVE_POOL: return LeavePoolTransactionConfirmation; case ExtrinsicType.STAKING_BOND: - case ExtrinsicType.JOIN_YIELD_POOL: return BondTransactionConfirmation; case ExtrinsicType.STAKING_UNBOND: return UnbondTransactionConfirmation; diff --git a/packages/extension-koni-ui/src/Popup/Confirmations/variants/Transaction/variants/JoinPool.tsx b/packages/extension-koni-ui/src/Popup/Confirmations/variants/Transaction/variants/JoinPool.tsx index 6382cf8907..982388b673 100644 --- a/packages/extension-koni-ui/src/Popup/Confirmations/variants/Transaction/variants/JoinPool.tsx +++ b/packages/extension-koni-ui/src/Popup/Confirmations/variants/Transaction/variants/JoinPool.tsx @@ -1,7 +1,7 @@ // Copyright 2019-2022 @subwallet/extension-koni-ui authors & contributors // SPDX-License-Identifier: Apache-2.0 -import { RequestStakePoolingBonding } from '@subwallet/extension-base/background/KoniTypes'; +import { RequestYieldStepSubmit, SubmitJoinNominationPool } from '@subwallet/extension-base/types'; import CommonTransactionInfo from '@subwallet/extension-koni-ui/components/Confirmation/CommonTransactionInfo'; import MetaInfo from '@subwallet/extension-koni-ui/components/MetaInfo/MetaInfo'; import useGetNativeTokenBasicInfo from '@subwallet/extension-koni-ui/hooks/common/useGetNativeTokenBasicInfo'; @@ -16,7 +16,8 @@ type Props = BaseTransactionConfirmationProps; const Component: React.FC = (props: Props) => { const { className, transaction } = props; - const data = transaction.data as RequestStakePoolingBonding; + const requestData = transaction.data as RequestYieldStepSubmit; + const data = requestData.data as SubmitJoinNominationPool; const { t } = useTranslation(); const { decimals, symbol } = useGetNativeTokenBasicInfo(transaction.chain); @@ -31,11 +32,11 @@ const Component: React.FC = (props: Props) => { className={'meta-info'} hasBackgroundWrapper > - {/* */} + {/* { +export async function submitPoolBonding (request: RequestYieldStepSubmit): Promise { return sendMessage('pri(bonding.nominationPool.submitBonding)', request); } From 9550ad703922dfeb7b75fbc6ab5ee4ca9016eafa Mon Sep 17 00:00:00 2001 From: tunghp2002 Date: Thu, 17 Oct 2024 18:06:46 +0700 Subject: [PATCH 2/4] [Fixed] - History transaction input data --- .../src/services/transaction-service/index.ts | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/packages/extension-base/src/services/transaction-service/index.ts b/packages/extension-base/src/services/transaction-service/index.ts index 08e319d924..70219e4d4f 100644 --- a/packages/extension-base/src/services/transaction-service/index.ts +++ b/packages/extension-base/src/services/transaction-service/index.ts @@ -20,7 +20,7 @@ import { getBaseTransactionInfo, getTransactionId, isSubstrateTransaction, isTon import { SWTransaction, SWTransactionInput, SWTransactionResponse, TransactionEmitter, TransactionEventMap, TransactionEventResponse, ValidateTransactionResponseInput } from '@subwallet/extension-base/services/transaction-service/types'; import { getExplorerLink, parseTransactionData } from '@subwallet/extension-base/services/transaction-service/utils'; import { isWalletConnectRequest } from '@subwallet/extension-base/services/wallet-connect-service/helpers'; -import { AccountJson, BasicTxErrorType, BasicTxWarningCode, LeavePoolAdditionalData, RequestStakePoolingBonding, RequestYieldStepSubmit, SpecialYieldPoolInfo, Web3Transaction, YieldPoolType } from '@subwallet/extension-base/types'; +import { AccountJson, BasicTxErrorType, BasicTxWarningCode, LeavePoolAdditionalData, RequestStakePoolingBonding, RequestYieldStepSubmit, SpecialYieldPoolInfo, SubmitJoinNominationPool, Web3Transaction, YieldPoolType } from '@subwallet/extension-base/types'; import { _isRuntimeUpdated, anyNumberToBN, pairToAccount, reformatAddress } from '@subwallet/extension-base/utils'; import { mergeTransactionAndSignature } from '@subwallet/extension-base/utils/eth/mergeTransactionAndSignature'; import { isContractAddress, parseContractInput } from '@subwallet/extension-base/utils/eth/parseTransaction'; @@ -402,11 +402,12 @@ export default class TransactionService { } break; - case ExtrinsicType.STAKING_JOIN_POOL: { - const data = parseTransactionData(transaction.data); + case ExtrinsicType.JOIN_YIELD_POOL: { + const data = parseTransactionData(transaction.data); + const poolData = data.data as SubmitJoinNominationPool; - historyItem.amount = { ...baseNativeAmount, value: data.amount || '0' }; - historyItem.to = data.selectedPool.name || data.selectedPool.id.toString(); + historyItem.amount = { ...baseNativeAmount, value: poolData.amount || '0' }; + historyItem.to = poolData.selectedPool.name || poolData.selectedPool.id.toString(); } break; @@ -717,7 +718,7 @@ export default class TransactionService { } catch (e) { console.error(e); } - } else if ([ExtrinsicType.STAKING_BOND, ExtrinsicType.STAKING_UNBOND, ExtrinsicType.STAKING_WITHDRAW, ExtrinsicType.STAKING_CANCEL_UNSTAKE, ExtrinsicType.STAKING_CLAIM_REWARD, ExtrinsicType.STAKING_JOIN_POOL, ExtrinsicType.STAKING_POOL_WITHDRAW, ExtrinsicType.STAKING_LEAVE_POOL].includes(transaction.extrinsicType)) { + } else if ([ExtrinsicType.STAKING_BOND, ExtrinsicType.STAKING_UNBOND, ExtrinsicType.STAKING_WITHDRAW, ExtrinsicType.STAKING_CANCEL_UNSTAKE, ExtrinsicType.STAKING_CLAIM_REWARD, ExtrinsicType.JOIN_YIELD_POOL, ExtrinsicType.STAKING_POOL_WITHDRAW, ExtrinsicType.STAKING_LEAVE_POOL].includes(transaction.extrinsicType)) { this.state.eventService.emit('transaction.submitStaking', transaction.chain); } else if (transaction.extrinsicType === ExtrinsicType.SWAP) { const inputData = parseTransactionData(transaction.data); From 43b3d13a0b7be85bc707972eb3728269aa3c48ca Mon Sep 17 00:00:00 2001 From: tunghp2002 Date: Thu, 17 Oct 2024 18:24:59 +0700 Subject: [PATCH 3/4] [Update] - Change unstake type of native staking --- .../earning-service/handlers/native-staking/amplitude.ts | 2 +- .../services/earning-service/handlers/native-staking/astar.ts | 2 +- .../earning-service/handlers/native-staking/para-chain.ts | 2 +- .../earning-service/handlers/native-staking/relay-chain.ts | 2 +- .../src/services/earning-service/handlers/native-staking/tao.ts | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/extension-base/src/services/earning-service/handlers/native-staking/amplitude.ts b/packages/extension-base/src/services/earning-service/handlers/native-staking/amplitude.ts index b613f527b1..2d66422ad2 100644 --- a/packages/extension-base/src/services/earning-service/handlers/native-staking/amplitude.ts +++ b/packages/extension-base/src/services/earning-service/handlers/native-staking/amplitude.ts @@ -563,7 +563,7 @@ export default class AmplitudeNativeStakingPoolHandler extends BaseParaNativeSta extrinsic = chainApi.api.tx.parachainStaking.leaveDelegators(); } - return [ExtrinsicType.STAKING_LEAVE_POOL, extrinsic]; + return [ExtrinsicType.STAKING_UNBOND, extrinsic]; } /* Leave pool action */ diff --git a/packages/extension-base/src/services/earning-service/handlers/native-staking/astar.ts b/packages/extension-base/src/services/earning-service/handlers/native-staking/astar.ts index 32aee7bf94..58f0f2a977 100644 --- a/packages/extension-base/src/services/earning-service/handlers/native-staking/astar.ts +++ b/packages/extension-base/src/services/earning-service/handlers/native-staking/astar.ts @@ -459,7 +459,7 @@ export default class AstarNativeStakingPoolHandler extends BaseParaNativeStaking const extrinsic = chainApi.api.tx.dappsStaking.unbondAndUnstake(dappParam, binaryAmount); - return [ExtrinsicType.STAKING_LEAVE_POOL, extrinsic]; + return [ExtrinsicType.STAKING_UNBOND, extrinsic]; } /* Leave pool action */ diff --git a/packages/extension-base/src/services/earning-service/handlers/native-staking/para-chain.ts b/packages/extension-base/src/services/earning-service/handlers/native-staking/para-chain.ts index 5ae44563a0..563c063086 100644 --- a/packages/extension-base/src/services/earning-service/handlers/native-staking/para-chain.ts +++ b/packages/extension-base/src/services/earning-service/handlers/native-staking/para-chain.ts @@ -606,7 +606,7 @@ export default class ParaNativeStakingPoolHandler extends BaseParaNativeStakingP extrinsic = apiPromise.api.tx.parachainStaking.scheduleRevokeDelegation(selectedTarget); } - return [ExtrinsicType.STAKING_LEAVE_POOL, extrinsic]; + return [ExtrinsicType.STAKING_UNBOND, extrinsic]; } /* Leave pool action */ diff --git a/packages/extension-base/src/services/earning-service/handlers/native-staking/relay-chain.ts b/packages/extension-base/src/services/earning-service/handlers/native-staking/relay-chain.ts index 674174d33c..defd6d7842 100644 --- a/packages/extension-base/src/services/earning-service/handlers/native-staking/relay-chain.ts +++ b/packages/extension-base/src/services/earning-service/handlers/native-staking/relay-chain.ts @@ -774,7 +774,7 @@ export default class RelayNativeStakingPoolHandler extends BaseNativeStakingPool extrinsic = chainApi.api.tx.staking.unbond(binaryAmount); } - return [ExtrinsicType.STAKING_LEAVE_POOL, extrinsic]; + return [ExtrinsicType.STAKING_UNBOND, extrinsic]; } /* Leave pool action */ diff --git a/packages/extension-base/src/services/earning-service/handlers/native-staking/tao.ts b/packages/extension-base/src/services/earning-service/handlers/native-staking/tao.ts index 971b94246a..d5f46cb1b8 100644 --- a/packages/extension-base/src/services/earning-service/handlers/native-staking/tao.ts +++ b/packages/extension-base/src/services/earning-service/handlers/native-staking/tao.ts @@ -466,7 +466,7 @@ export default class TaoNativeStakingPoolHandler extends BaseParaStakingPoolHand const extrinsic = apiPromise.api.tx.subtensorModule.removeStake(selectedTarget, binaryAmount); - return [ExtrinsicType.STAKING_LEAVE_POOL, extrinsic]; + return [ExtrinsicType.STAKING_UNBOND, extrinsic]; } /* Leave pool action */ From 7a3e7bd7784351652b11519a505e8e22b36b08c0 Mon Sep 17 00:00:00 2001 From: tunghp2002 Date: Fri, 18 Oct 2024 11:42:06 +0700 Subject: [PATCH 4/4] [Update] - Remove some STAKING_POOL_WITHDRAW type --- .../src/koni/api/yield/helper/utils.ts | 3 +-- .../src/services/transaction-service/index.ts | 2 +- .../Confirmations/variants/Transaction/index.tsx | 2 +- .../variants/Transaction/variants/JoinPool.tsx | 15 ++++++++------- .../src/messaging/transaction/staking.ts | 6 +++--- 5 files changed, 14 insertions(+), 14 deletions(-) diff --git a/packages/extension-base/src/koni/api/yield/helper/utils.ts b/packages/extension-base/src/koni/api/yield/helper/utils.ts index f08513fd46..a63393dd23 100644 --- a/packages/extension-base/src/koni/api/yield/helper/utils.ts +++ b/packages/extension-base/src/koni/api/yield/helper/utils.ts @@ -21,8 +21,7 @@ export const YIELD_EXTRINSIC_TYPES = [ ExtrinsicType.REDEEM_STDOT, ExtrinsicType.JOIN_YIELD_POOL, ExtrinsicType.STAKING_CLAIM_REWARD, - ExtrinsicType.STAKING_LEAVE_POOL, - ExtrinsicType.STAKING_POOL_WITHDRAW + ExtrinsicType.STAKING_LEAVE_POOL ]; export const YIELD_POOL_STAT_REFRESH_INTERVAL = 90000; diff --git a/packages/extension-base/src/services/transaction-service/index.ts b/packages/extension-base/src/services/transaction-service/index.ts index 70219e4d4f..e0a3822b72 100644 --- a/packages/extension-base/src/services/transaction-service/index.ts +++ b/packages/extension-base/src/services/transaction-service/index.ts @@ -718,7 +718,7 @@ export default class TransactionService { } catch (e) { console.error(e); } - } else if ([ExtrinsicType.STAKING_BOND, ExtrinsicType.STAKING_UNBOND, ExtrinsicType.STAKING_WITHDRAW, ExtrinsicType.STAKING_CANCEL_UNSTAKE, ExtrinsicType.STAKING_CLAIM_REWARD, ExtrinsicType.JOIN_YIELD_POOL, ExtrinsicType.STAKING_POOL_WITHDRAW, ExtrinsicType.STAKING_LEAVE_POOL].includes(transaction.extrinsicType)) { + } else if ([ExtrinsicType.STAKING_BOND, ExtrinsicType.STAKING_UNBOND, ExtrinsicType.STAKING_WITHDRAW, ExtrinsicType.STAKING_CANCEL_UNSTAKE, ExtrinsicType.STAKING_CLAIM_REWARD, ExtrinsicType.JOIN_YIELD_POOL, ExtrinsicType.STAKING_LEAVE_POOL].includes(transaction.extrinsicType)) { this.state.eventService.emit('transaction.submitStaking', transaction.chain); } else if (transaction.extrinsicType === ExtrinsicType.SWAP) { const inputData = parseTransactionData(transaction.data); diff --git a/packages/extension-web-ui/src/Popup/Confirmations/variants/Transaction/index.tsx b/packages/extension-web-ui/src/Popup/Confirmations/variants/Transaction/index.tsx index ee00739234..6aa6ad6d2c 100644 --- a/packages/extension-web-ui/src/Popup/Confirmations/variants/Transaction/index.tsx +++ b/packages/extension-web-ui/src/Popup/Confirmations/variants/Transaction/index.tsx @@ -33,11 +33,11 @@ const getTransactionComponent = (extrinsicType: ExtrinsicType): typeof BaseTrans case ExtrinsicType.SEND_NFT: return SendNftTransactionConfirmation; case ExtrinsicType.STAKING_JOIN_POOL: + case ExtrinsicType.JOIN_YIELD_POOL: return JoinPoolTransactionConfirmation; case ExtrinsicType.STAKING_LEAVE_POOL: return LeavePoolTransactionConfirmation; case ExtrinsicType.STAKING_BOND: - case ExtrinsicType.JOIN_YIELD_POOL: return BondTransactionConfirmation; case ExtrinsicType.STAKING_UNBOND: return UnbondTransactionConfirmation; diff --git a/packages/extension-web-ui/src/Popup/Confirmations/variants/Transaction/variants/JoinPool.tsx b/packages/extension-web-ui/src/Popup/Confirmations/variants/Transaction/variants/JoinPool.tsx index b578e54630..ff0a6073d7 100644 --- a/packages/extension-web-ui/src/Popup/Confirmations/variants/Transaction/variants/JoinPool.tsx +++ b/packages/extension-web-ui/src/Popup/Confirmations/variants/Transaction/variants/JoinPool.tsx @@ -1,7 +1,7 @@ // Copyright 2019-2022 @subwallet/extension-web-ui authors & contributors // SPDX-License-Identifier: Apache-2.0 -import { RequestStakePoolingBonding } from '@subwallet/extension-base/background/KoniTypes'; +import { RequestYieldStepSubmit, SubmitJoinNominationPool } from '@subwallet/extension-base/types'; import { AlertBox } from '@subwallet/extension-web-ui/components'; import CommonTransactionInfo from '@subwallet/extension-web-ui/components/Confirmation/CommonTransactionInfo'; import MetaInfo from '@subwallet/extension-web-ui/components/MetaInfo/MetaInfo'; @@ -17,7 +17,8 @@ type Props = BaseTransactionConfirmationProps; const Component: React.FC = (props: Props) => { const { className, transaction } = props; - const data = transaction.data as RequestStakePoolingBonding; + const requestData = transaction.data as RequestYieldStepSubmit; + const data = requestData.data as SubmitJoinNominationPool; const { t } = useTranslation(); const { decimals, symbol } = useGetNativeTokenBasicInfo(transaction.chain); @@ -32,11 +33,11 @@ const Component: React.FC = (props: Props) => { className={'meta-info'} hasBackgroundWrapper > - {/* */} + {/* { +export async function submitPoolBonding (request: RequestYieldStepSubmit): Promise { return sendMessage('pri(bonding.nominationPool.submitBonding)', request); }