Skip to content

Commit

Permalink
feat: add relay endpoints
Browse files Browse the repository at this point in the history
  • Loading branch information
iamacook committed Feb 27, 2024
1 parent 974e2a9 commit 59bbae7
Show file tree
Hide file tree
Showing 3 changed files with 80 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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'
Expand All @@ -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
Expand All @@ -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<RelayTransactionResponse> {
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<RelayCountResponse> {
return getEndpoint(baseUrl, '/v1/chains/{chainId}/relay/{address}', { path: { chainId, address } })
}

/**
* Get basic information about a Safe. E.g. owners, modules, version etc
*/
Expand Down
47 changes: 47 additions & 0 deletions src/types/api.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import type {
AuthorizationEmailRequestHeaders,
VerifyEmailRequestBody,
} from './emails'
import type { RelayCountResponse, RelayTransactionRequest, RelayTransactionResponse } from './relay'

export type Primitive = string | number | boolean | null

Expand Down Expand Up @@ -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']
Expand Down Expand Up @@ -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: {
Expand Down
15 changes: 15 additions & 0 deletions src/types/relay.ts
Original file line number Diff line number Diff line change
@@ -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;
}

0 comments on commit 59bbae7

Please sign in to comment.