Skip to content

Commit

Permalink
Feat: staking deposit decoding (#196)
Browse files Browse the repository at this point in the history
  • Loading branch information
katspaugh authored Aug 30, 2024
1 parent c97fe9b commit ce596fc
Show file tree
Hide file tree
Showing 4 changed files with 67 additions and 15 deletions.
11 changes: 6 additions & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand Down Expand Up @@ -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<BaselineConfirmationView | OrderConfirmationView> {
value?: operations['data_decoder']['parameters']['body']['value'],
): Promise<AnyConfirmationView> {
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 },
})
}

Expand Down
9 changes: 2 additions & 7 deletions src/types/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -836,7 +831,7 @@ export interface operations {
}
responses: {
200: {
schema: BaselineConfirmationView | OrderConfirmationView
schema: AnyConfirmationView
}
}
}
Expand Down
45 changes: 43 additions & 2 deletions src/types/decoded-data.ts
Original file line number Diff line number Diff line change
@@ -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[]
Expand Down Expand Up @@ -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 &
Expand All @@ -52,4 +57,40 @@ export type TwapOrderConfirmationView = {
} & DecodedDataResponse &
Omit<TwapOrder, 'type' | 'humanDescription' | 'richDecodedInfo'>

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
17 changes: 16 additions & 1 deletion src/types/transactions.ts
Original file line number Diff line number Diff line change
@@ -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[]
Expand Down Expand Up @@ -71,6 +72,7 @@ export enum TransactionInfoType {
SWAP_ORDER = 'SwapOrder',
TWAP_ORDER = 'TwapOrder',
SWAP_TRANSFER = 'SwapTransfer',
NATIVE_STAKING_DEPOSIT = 'NativeStakingDeposit',
}

export enum ConflictType {
Expand Down Expand Up @@ -338,7 +340,20 @@ export type TwapOrder = Omit<BaseOrder, 'executedBuyAmount' | 'executedSellAmoun
// Discriminated union type
export type Order = SwapOrder | SwapTransferOrder | TwapOrder

export type TransactionInfo = Transfer | SettingsChange | Custom | MultiSend | Cancellation | Creation | Order
export type StakingTxInfo = {
type: TransactionInfoType.NATIVE_STAKING_DEPOSIT
humanDescription?: string
} & Omit<NativeStakingDepositConfirmationView, 'type'>

export type TransactionInfo =
| Transfer
| SettingsChange
| Custom
| MultiSend
| Cancellation
| Creation
| Order
| StakingTxInfo

export type ModuleExecutionInfo = {
type: DetailedExecutionInfoType.MODULE
Expand Down

0 comments on commit ce596fc

Please sign in to comment.