From 59bbae735737f3c9ce1e7c4fd23b4f09dc7c833e Mon Sep 17 00:00:00 2001 From: iamacook Date: Tue, 27 Feb 2024 18:13:03 +0100 Subject: [PATCH 1/3] feat: add relay endpoints --- src/index.ts | 18 ++++++++++++++++++ src/types/api.ts | 47 ++++++++++++++++++++++++++++++++++++++++++++++ src/types/relay.ts | 15 +++++++++++++++ 3 files changed, 80 insertions(+) create mode 100644 src/types/relay.ts 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 From 1f8db3908ac3e4daee71727ff2130d38aab9fe51 Mon Sep 17 00:00:00 2001 From: iamacook Date: Tue, 27 Feb 2024 18:18:21 +0100 Subject: [PATCH 2/3] fix: add newline at end of file --- src/types/relay.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/types/relay.ts b/src/types/relay.ts index 2913fa39..a74e87ec 100644 --- a/src/types/relay.ts +++ b/src/types/relay.ts @@ -12,4 +12,4 @@ export type RelayTransactionResponse = { export type RelayCountResponse = { remaining: number; limit: number; -} \ No newline at end of file +} From 323416c2a7f728812bc8f060fdbb36951de70c0b Mon Sep 17 00:00:00 2001 From: iamacook Date: Tue, 27 Feb 2024 18:21:23 +0100 Subject: [PATCH 3/3] fix: lint --- src/index.ts | 3 ++- src/types/api.ts | 5 ++--- src/types/relay.ts | 14 +++++++------- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/src/index.ts b/src/index.ts index 7a476d6e..076b581b 100644 --- a/src/index.ts +++ b/src/index.ts @@ -56,7 +56,8 @@ export const setBaseUrl = (url: string): void => { */ export function relayTransaction( chainId: string, - body: operations['relay_transaction']['parameters']['body']): Promise { + body: operations['relay_transaction']['parameters']['body'], +): Promise { return postEndpoint(baseUrl, '/v1/chains/{chainId}/relay', { path: { chainId }, body }) } diff --git a/src/types/api.ts b/src/types/api.ts index 4db9785e..9cba604b 100644 --- a/src/types/api.ts +++ b/src/types/api.ts @@ -97,9 +97,8 @@ export interface paths extends PathRegistry { path: { chainId: string } - } - }, + } '/v1/chains/{chainId}/relay/{address}': { get: operations['relay_count'] parameters: { @@ -108,7 +107,7 @@ export interface paths extends PathRegistry { address: string } } - }, + } '/v1/chains/{chainId}/safes/{address}': { /** Get status of the safe */ get: operations['safes_read'] diff --git a/src/types/relay.ts b/src/types/relay.ts index a74e87ec..43a195f6 100644 --- a/src/types/relay.ts +++ b/src/types/relay.ts @@ -1,15 +1,15 @@ export type RelayTransactionRequest = { - version: string; - to: string; - data: string; - gasLimit?: string; + version: string + to: string + data: string + gasLimit?: string } export type RelayTransactionResponse = { - taskId: string; + taskId: string } export type RelayCountResponse = { - remaining: number; - limit: number; + remaining: number + limit: number }