Skip to content

Commit

Permalink
Feat: transaction preview endpoint (#205)
Browse files Browse the repository at this point in the history
  • Loading branch information
katspaugh authored Nov 20, 2024
1 parent 34be8d8 commit 42b31eb
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import type {
SafeModuleTransactionsResponse,
SafeMultisigTransactionsResponse,
NoncesResponse,
TransactionPreview,
} from './types/transactions'
import type {
EthereumAddress,
Expand Down Expand Up @@ -312,6 +313,22 @@ export function getConfirmationView(
})
}

/**
* Get a tx preview
*/
export function getTxPreview(
chainId: string,
safeAddress: string,
data: operations['data_decoder']['parameters']['body']['data'],
to?: operations['data_decoder']['parameters']['body']['to'],
value?: operations['data_decoder']['parameters']['body']['value'],
): Promise<TransactionPreview> {
return postEndpoint(baseUrl, '/v1/chains/{chainId}/transactions/{safe_address}/preview', {
path: { chainId, safe_address: safeAddress },
body: { data, to, value },
})
}

/**
* Returns all defined chain configs
*/
Expand Down
28 changes: 28 additions & 0 deletions src/types/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import type {
SafeModuleTransactionsResponse,
SafeMultisigTransactionsResponse,
NoncesResponse,
TransactionPreview,
} from './transactions'
import type { SafeInfo, SafeOverview } from './safe-info'
import type { ChainListResponse, ChainInfo, ChainIndexingStatus } from './chains'
Expand Down Expand Up @@ -248,6 +249,15 @@ export interface paths extends PathRegistry {
}
}
}
'/v1/chains/{chainId}/transactions/{safe_address}/preview': {
post: operations['preview_transaction']
parameters: {
path: {
chainId: string
safe_address: string
}
}
}
'/v1/chains/{chainId}/safes/{safe_address}/views/transaction-confirmation': {
post: operations['get_transaction_confirmation_view']
parameters: {
Expand Down Expand Up @@ -828,6 +838,24 @@ export interface operations {
422: unknown
}
}
preview_transaction: {
parameters: {
path: {
chainId: string
safe_address: string
}
body: DecodedDataRequest
}
responses: {
200: {
schema: TransactionPreview
}
/** Safe not found */
404: unknown
/** Safe address checksum not valid */
422: unknown
}
}
get_transaction_confirmation_view: {
parameters: {
path: {
Expand Down
5 changes: 5 additions & 0 deletions src/types/transactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,11 @@ export type TransactionDetails = {

/* Transaction details types end */

export type TransactionPreview = {
txInfo: TransactionInfo
txData: TransactionData
}

/* Transaction estimation types */

export type SafeTransactionEstimationRequest = {
Expand Down

0 comments on commit 42b31eb

Please sign in to comment.