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: transaction preview endpoint #205

Merged
merged 1 commit into from
Nov 20, 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
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
Loading