From 1047ccae707be93e72d0a0fe59fee5c9b2e88809 Mon Sep 17 00:00:00 2001 From: James Campbell Date: Fri, 12 Jan 2024 13:31:59 +0100 Subject: [PATCH 1/4] Improve condition for Commitment button and display commitment end date --- src/pages/Staking/StakeDetailsPage/index.tsx | 10 ++++- src/store/staking-applications/slice.ts | 1 + src/threshold-ts/applications/index.ts | 42 ++++++++++++++++++++ 3 files changed, 52 insertions(+), 1 deletion(-) diff --git a/src/pages/Staking/StakeDetailsPage/index.tsx b/src/pages/Staking/StakeDetailsPage/index.tsx index 36c638576..4255e0e28 100644 --- a/src/pages/Staking/StakeDetailsPage/index.tsx +++ b/src/pages/Staking/StakeDetailsPage/index.tsx @@ -75,6 +75,12 @@ const StakeDetailsPage: FC = () => { stakingProviderAddress || AddressZero ) + const endCommitment = tacoApp.stakingProviderInfo?.endCommitment + const isCommited = (Number(endCommitment) ?? 0) > 0 + const endCommitmentDate = new Date( + (Number(endCommitment) ?? 0) * 1000 + ).toLocaleDateString() + const isInActiveStake = BigNumber.from(stake?.totalInTStake ?? "0").isZero() const { total: rewardsForStake } = useAppSelector((state) => @@ -166,10 +172,12 @@ const StakeDetailsPage: FC = () => { - {tacoApp.isAuthorized && ( + {tacoApp.isAuthorized && !isCommited ? ( + ) : ( +

Your commitment ends on {endCommitmentDate}

)} ) : ( diff --git a/src/store/staking-applications/slice.ts b/src/store/staking-applications/slice.ts index 4cd0fe065..df6712064 100644 --- a/src/store/staking-applications/slice.ts +++ b/src/store/staking-applications/slice.ts @@ -287,6 +287,7 @@ export const stakingApplicationsSlice = createSlice({ deauthorizationCreatedAt: undefined, isOperatorInPool: undefined, operator: AddressZero, + stakingProviderInfo: undefined, } state.randomBeacon.stakingProviders.data[stakingProvider] = { diff --git a/src/threshold-ts/applications/index.ts b/src/threshold-ts/applications/index.ts index cecbb2985..674efe2f9 100644 --- a/src/threshold-ts/applications/index.ts +++ b/src/threshold-ts/applications/index.ts @@ -38,6 +38,20 @@ export interface AuthorizationParameters< authorizationDecreaseChangePeriod: NumberType } +export interface StakingProviderInfo< + NumberType extends BigNumberish = BigNumber +> { + operator: string + operatorConfirmed: boolean + operatorStartTimestamp: NumberType + authorized: NumberType + deauthorizing: NumberType + endDeauthorization: NumberType + tReward: NumberType + rewardPerTokenPaid: NumberType + endCommitment: NumberType +} + export interface StakingProviderAppInfo< NumberType extends BigNumberish = BigNumber > { @@ -75,6 +89,8 @@ export interface StakingProviderAppInfo< * it means that the operator for a given staking provider is not set. */ isOperatorInPool: boolean | undefined + + stakingProviderInfo?: StakingProviderInfo | undefined } /** @@ -202,6 +218,8 @@ export interface IApplication { */ stakingProviderToOperator(stakingProvider: string): Promise + stakingProviderInfo(stakingProvider: string): Promise + /** * Used to get staking provider address mapped to the given registered * operator address @@ -314,6 +332,15 @@ export class Application implements IApplication { }, ] + const tacoCalls: ContractCall[] = [ + { + interface: this.contract.interface, + address: this.contract.address, + method: "stakingProviderInfo", + args: [stakingProvider], + }, + ] + const [ authorizedStake, pendingAuthorizationDecrease, @@ -323,6 +350,14 @@ export class Application implements IApplication { [operator], ] = await this._multicall.aggregate(calls) + let stakingProviderInfo + try { + ;[stakingProviderInfo] = await this._multicall.aggregate(tacoCalls) + } catch (error) { + console.warn("Failed to aggregate tacoCalls", error) + stakingProviderInfo = undefined + } + let isOperatorInPool = undefined if (operator && !isAddressZero(operator)) { try { @@ -368,6 +403,7 @@ export class Application implements IApplication { deauthorizationCreatedAt, isOperatorInPool, operator, + stakingProviderInfo, } } @@ -448,6 +484,12 @@ export class Application implements IApplication { ) } + stakingProviderInfo = async ( + stakingProvider: string + ): Promise => { + return await this._application.stakingProviderInfo(stakingProvider) + } + stakingProviderToOperator = async ( stakingProvider: string ): Promise => { From 0551ab5dbdadb4f788f9c403bfce938a303c6e67 Mon Sep 17 00:00:00 2001 From: James Campbell Date: Fri, 19 Jan 2024 14:51:02 +0100 Subject: [PATCH 2/4] Add wording about commitment to topup modal --- src/components/Modal/TopupTModal/TopUpTModal.tsx | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/components/Modal/TopupTModal/TopUpTModal.tsx b/src/components/Modal/TopupTModal/TopUpTModal.tsx index c15809a26..c8ce08e43 100644 --- a/src/components/Modal/TopupTModal/TopUpTModal.tsx +++ b/src/components/Modal/TopupTModal/TopUpTModal.tsx @@ -61,6 +61,9 @@ const TopupTModal: FC< If you want to put your new topped-up tokens at work, make sure to increase the authorization to your applications. +
+ If you increase the Authorization to TACo, the new tokens will be + subject to the same lock-up period as your current stake.
Date: Tue, 23 Jan 2024 13:53:16 +0100 Subject: [PATCH 3/4] Show alert when trying to Deauth during Taco commitment period --- .../index.tsx | 24 +++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/src/pages/Staking/AuthorizeStakingApps/AuthorizeApplicationsCardCheckbox/index.tsx b/src/pages/Staking/AuthorizeStakingApps/AuthorizeApplicationsCardCheckbox/index.tsx index aa42c3c3a..b436c1a8c 100644 --- a/src/pages/Staking/AuthorizeStakingApps/AuthorizeApplicationsCardCheckbox/index.tsx +++ b/src/pages/Staking/AuthorizeStakingApps/AuthorizeApplicationsCardCheckbox/index.tsx @@ -35,6 +35,7 @@ import { formatDate } from "../../../../utils/date" import { calculatePercenteage } from "../../../../utils/percentage" import { StakingAppForm } from "../../../../components/StakingApplicationForms" import { AuthorizationStatus } from "../../../../types" +import { StakingProviderInfo } from "../../../../threshold-ts/applications" interface CommonProps { stakingAppId: StakingAppName @@ -58,6 +59,7 @@ type StakingAppAuthDataBaseProps = { remainingAuthorizationDecreaseDelay: string isOperatorInPool: boolean | undefined operator: string + stakingProviderInfo?: StakingProviderInfo | undefined } type AppAuthDataConditionalProps = @@ -255,8 +257,26 @@ export const AuthorizeApplicationsCardCheckboxBase: FC< } const onSubmitForm = (tokenAmount: string) => { - if (isIncreaseAction) onAuthorizeApp(tokenAmount) - else onInitiateDeauthorization(tokenAmount) + if (isIncreaseAction) { + onAuthorizeApp(tokenAmount) + } else { + if (appAuthData.stakingAppId === "taco") { + // const endCommitment = appAuthData.stakingProviderInfo?.endCommitment + const endCommitment = appAuthData.stakingProviderInfo?.endCommitment + const currentTime = Math.floor(Date.now() / 1000) + const isCommited = (Number(endCommitment) ?? 0) > currentTime + const endCommitmentDate = new Date( + (Number(endCommitment) ?? 0) * 1000 + ).toLocaleDateString() + if (isCommited) { + alert(`You are still committed until ${endCommitmentDate}.`) + } else { + onInitiateDeauthorization(tokenAmount) + } + } else { + onInitiateDeauthorization(tokenAmount) + } + } } const onConfirmDeauthorization = () => { From cf36d0821939c3926752c2ad0cae1d83e1efc937 Mon Sep 17 00:00:00 2001 From: James Campbell Date: Thu, 1 Feb 2024 11:06:40 +0100 Subject: [PATCH 4/4] Improve wording when topping up or de-authing Co-authored-by: Arjun Hassard --- src/components/Modal/TopupTModal/TopUpTModal.tsx | 12 ++++++++---- .../AuthorizeApplicationsCardCheckbox/index.tsx | 4 +++- 2 files changed, 11 insertions(+), 5 deletions(-) diff --git a/src/components/Modal/TopupTModal/TopUpTModal.tsx b/src/components/Modal/TopupTModal/TopUpTModal.tsx index c8ce08e43..11eb3009f 100644 --- a/src/components/Modal/TopupTModal/TopUpTModal.tsx +++ b/src/components/Modal/TopupTModal/TopUpTModal.tsx @@ -59,11 +59,15 @@ const TopupTModal: FC< your initial stake. - If you want to put your new topped-up tokens at work, make sure to - increase the authorization to your applications. + If you want to put newly topped-up tokens to work, make sure to + individually increase the total authorization to each Threshold + application (tBTC, Random Beacon & TACo).
- If you increase the Authorization to TACo, the new tokens will be - subject to the same lock-up period as your current stake. + If you increase the total number of tokens authorized to the TACo + app, those tokens will automatically be subject to the same unlock + horizon as your current TACo stake, including the min. + deauthorization delay (6 months), plus any lock-up extension on + top of that.