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: add relay endpoints #152

Merged
merged 3 commits into from
Feb 27, 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
19 changes: 19 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,23 @@ 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
46 changes: 46 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,23 @@ 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 +402,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
}
Loading