Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat: staking deposit decoding #196

Merged
merged 7 commits into from
Aug 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading