diff --git a/src/index.ts b/src/index.ts index ef929003..7a476d6e 100644 --- a/src/index.ts +++ b/src/index.ts @@ -26,6 +26,7 @@ import type { SafeMessage, SafeMessageListPage } from './types/safe-messages' import { DEFAULT_BASE_URL } from './config' import type { DelegateResponse, DelegatesRequest } from './types/delegates' import type { GetEmailResponse } from './types/emails' +import type { RelayCountResponse, RelayTransactionResponse } from './types/relay' export * from './types/safe-info' export * from './types/safe-apps' @@ -36,6 +37,7 @@ export * from './types/master-copies' export * from './types/decoded-data' export * from './types/safe-messages' export * from './types/notifications' +export * from './types/relay' // Can be set externally to a different CGW host let baseUrl: string = DEFAULT_BASE_URL @@ -49,6 +51,22 @@ export const setBaseUrl = (url: string): void => { /* eslint-disable @typescript-eslint/explicit-module-boundary-types */ +/** + * Relay a transaction from a Safe + */ +export function relayTransaction( + chainId: string, + body: operations['relay_transaction']['parameters']['body']): Promise { + return postEndpoint(baseUrl, '/v1/chains/{chainId}/relay', { path: { chainId }, body }) +} + +/** + * Get the relay limit and number of remaining relays remaining + */ +export function getRelayCount(chainId: string, address: string): Promise { + return getEndpoint(baseUrl, '/v1/chains/{chainId}/relay/{address}', { path: { chainId, address } }) +} + /** * Get basic information about a Safe. E.g. owners, modules, version etc */ diff --git a/src/types/api.ts b/src/types/api.ts index 1952859d..4db9785e 100644 --- a/src/types/api.ts +++ b/src/types/api.ts @@ -37,6 +37,7 @@ import type { AuthorizationEmailRequestHeaders, VerifyEmailRequestBody, } from './emails' +import type { RelayCountResponse, RelayTransactionRequest, RelayTransactionResponse } from './relay' export type Primitive = string | number | boolean | null @@ -90,6 +91,24 @@ interface PathRegistry { } export interface paths extends PathRegistry { + '/v1/chains/{chainId}/relay': { + post: operations['relay_transaction'] + parameters: { + path: { + chainId: string + } + + } + }, + '/v1/chains/{chainId}/relay/{address}': { + get: operations['relay_count'] + parameters: { + path: { + chainId: string + address: string + } + } + }, '/v1/chains/{chainId}/safes/{address}': { /** Get status of the safe */ get: operations['safes_read'] @@ -384,6 +403,34 @@ export interface paths extends PathRegistry { } export interface operations { + /** Relay a transaction */ + relay_transaction: { + parameters: { + path: { + chainId: string + } + body: RelayTransactionRequest + } + responses: { + 200: { + schema: RelayTransactionResponse + } + } + } + /** Get the limit and current number of relays */ + relay_count: { + parameters: { + path: { + chainId: string + address: string + } + } + responses: { + 200: { + schema: RelayCountResponse + } + } + } /** Get status of the safe */ safes_read: { parameters: { diff --git a/src/types/relay.ts b/src/types/relay.ts new file mode 100644 index 00000000..2913fa39 --- /dev/null +++ b/src/types/relay.ts @@ -0,0 +1,15 @@ +export type RelayTransactionRequest = { + version: string; + to: string; + data: string; + gasLimit?: string; +} + +export type RelayTransactionResponse = { + taskId: string; +} + +export type RelayCountResponse = { + remaining: number; + limit: number; +} \ No newline at end of file