From ce596fc73915f3ae21d3277bbec6ec2918cfb4ec Mon Sep 17 00:00:00 2001 From: katspaugh <381895+katspaugh@users.noreply.github.com> Date: Fri, 30 Aug 2024 13:13:09 +0200 Subject: [PATCH] Feat: staking deposit decoding (#196) --- src/index.ts | 11 +++++----- src/types/api.ts | 9 ++------ src/types/decoded-data.ts | 45 +++++++++++++++++++++++++++++++++++++-- src/types/transactions.ts | 17 ++++++++++++++- 4 files changed, 67 insertions(+), 15 deletions(-) diff --git a/src/index.ts b/src/index.ts index 60181322..014cac74 100644 --- a/src/index.ts +++ b/src/index.ts @@ -22,7 +22,7 @@ import type { SafeInfo, SafeOverview } from './types/safe-info' import type { ChainListResponse, ChainInfo } from './types/chains' import type { SafeAppsResponse } from './types/safe-apps' import type { MasterCopyReponse } from './types/master-copies' -import type { BaselineConfirmationView, OrderConfirmationView, DecodedDataResponse } from './types/decoded-data' +import type { AnyConfirmationView, DecodedDataResponse } from './types/decoded-data' import type { SafeMessage, SafeMessageListPage } from './types/safe-messages' import { DEFAULT_BASE_URL } from './config' import type { DelegateResponse, DelegatesRequest } from './types/delegates' @@ -302,12 +302,13 @@ export function proposeTransaction( export function getConfirmationView( chainId: string, safeAddress: string, - encodedData: operations['data_decoder']['parameters']['body']['data'], + data: operations['data_decoder']['parameters']['body']['data'], to?: operations['data_decoder']['parameters']['body']['to'], -): Promise { + value?: operations['data_decoder']['parameters']['body']['value'], +): Promise { return postEndpoint(baseUrl, '/v1/chains/{chainId}/safes/{safe_address}/views/transaction-confirmation', { - path: { chainId: chainId, safe_address: safeAddress }, - body: { data: encodedData, to }, + path: { chainId, safe_address: safeAddress }, + body: { data, to, value }, }) } diff --git a/src/types/api.ts b/src/types/api.ts index 5e530c82..c9300ef0 100644 --- a/src/types/api.ts +++ b/src/types/api.ts @@ -20,12 +20,7 @@ import type { import type { SafeInfo, SafeOverview } from './safe-info' import type { ChainListResponse, ChainInfo } from './chains' import type { SafeAppsResponse } from './safe-apps' -import type { - BaselineConfirmationView, - OrderConfirmationView, - DecodedDataRequest, - DecodedDataResponse, -} from './decoded-data' +import type { AnyConfirmationView, DecodedDataRequest, DecodedDataResponse } from './decoded-data' import type { MasterCopyReponse } from './master-copies' import type { ConfirmSafeMessageRequest, @@ -836,7 +831,7 @@ export interface operations { } responses: { 200: { - schema: BaselineConfirmationView | OrderConfirmationView + schema: AnyConfirmationView } } } diff --git a/src/types/decoded-data.ts b/src/types/decoded-data.ts index 592b5f19..228e1216 100644 --- a/src/types/decoded-data.ts +++ b/src/types/decoded-data.ts @@ -1,13 +1,17 @@ +import type { TokenInfo } from './common' import type { SwapOrder, TwapOrder } from './transactions' export enum ConfirmationViewTypes { + GENERIC = 'GENERIC', COW_SWAP_ORDER = 'COW_SWAP_ORDER', COW_SWAP_TWAP_ORDER = 'COW_SWAP_TWAP_ORDER', + KILN_NATIVE_STAKING_DEPOSIT = 'KILN_NATIVE_STAKING_DEPOSIT', } export type DecodedDataRequest = { data: string to?: string + value?: string } type ParamValue = string | ParamValue[] @@ -39,9 +43,10 @@ export type DecodedDataResponse = { } export type BaselineConfirmationView = { - type: 'GENERIC' + type: ConfirmationViewTypes.GENERIC } & DecodedDataResponse +/* Swaps */ export type SwapOrderConfirmationView = { type: ConfirmationViewTypes.COW_SWAP_ORDER } & DecodedDataResponse & @@ -52,4 +57,40 @@ export type TwapOrderConfirmationView = { } & DecodedDataResponse & Omit -export type OrderConfirmationView = SwapOrderConfirmationView | TwapOrderConfirmationView +export type AnySwapOrderConfirmationView = SwapOrderConfirmationView | TwapOrderConfirmationView + +export enum NativeStakingStatus { + AWAITING_ENTRY = 'AWAITING_ENTRY', + REQUESTED_EXIT = 'REQUESTED_EXIT', + SIGNATURE_NEEDED = 'SIGNATURE_NEEDED', + AWAITING_EXECUTION = 'AWAITING_EXECUTION', + VALIDATION_STARTED = 'VALIDATION_STARTED', + WITHDRAWN = 'WITHDRAWN', + UNKNOWN = 'UNKNOWN', +} + +/* Staking */ +export type NativeStakingDepositConfirmationView = { + type: ConfirmationViewTypes.KILN_NATIVE_STAKING_DEPOSIT + status: NativeStakingStatus + estimatedEntryTime: number + estimatedExitTime: number + estimatedWithdrawalTime: number + fee: number + monthlyNrr: number + annualNrr: number + tokenInfo: TokenInfo + value: string + expectedAnnualReward: string + expectedMonthlyReward: string + expectedFiatAnnualReward: number + expectedFiatMonthlyReward: number + numValidators: number +} & DecodedDataResponse + +/* Union */ +export type AnyConfirmationView = + | BaselineConfirmationView + | SwapOrderConfirmationView + | TwapOrderConfirmationView + | NativeStakingDepositConfirmationView diff --git a/src/types/transactions.ts b/src/types/transactions.ts index 97500dcd..6a934fae 100644 --- a/src/types/transactions.ts +++ b/src/types/transactions.ts @@ -1,4 +1,5 @@ import type { AddressEx, Page, TokenInfo } from './common' +import type { NativeStakingDepositConfirmationView } from './decoded-data' import type { RichDecodedInfo } from './human-description' export type ParamValue = string | ParamValue[] @@ -71,6 +72,7 @@ export enum TransactionInfoType { SWAP_ORDER = 'SwapOrder', TWAP_ORDER = 'TwapOrder', SWAP_TRANSFER = 'SwapTransfer', + NATIVE_STAKING_DEPOSIT = 'NativeStakingDeposit', } export enum ConflictType { @@ -338,7 +340,20 @@ export type TwapOrder = Omit + +export type TransactionInfo = + | Transfer + | SettingsChange + | Custom + | MultiSend + | Cancellation + | Creation + | Order + | StakingTxInfo export type ModuleExecutionInfo = { type: DetailedExecutionInfoType.MODULE