From fcf4fef3b7f7605fa25284d53242cdc66bbe1c7d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ahmet=20Bu=C4=9Fra=20Yi=C4=9Fiter?= Date: Tue, 14 Jan 2025 14:24:46 +0300 Subject: [PATCH] Extract new relayer endpoints (#643) * Extract new relayer endpoints * Update comment * Add local relayer * Update provider relayer * Fix ts issues * Update * Update --- packages/relayer/src/index.ts | 11 +++++++++++ packages/relayer/src/local-relayer.ts | 15 ++++++++++++++- packages/relayer/src/provider-relayer.ts | 13 ++++++++++++- packages/relayer/src/rpc-relayer/index.ts | 13 +++++++++++++ 4 files changed, 50 insertions(+), 2 deletions(-) diff --git a/packages/relayer/src/index.ts b/packages/relayer/src/index.ts index 95a8eb287..48c29b8ec 100644 --- a/packages/relayer/src/index.ts +++ b/packages/relayer/src/index.ts @@ -54,6 +54,17 @@ export interface Relayer { delay?: number, maxFails?: number ): Promise + + // getMetaTransactions returns a list of meta transactions for a given project and gas tank + getMetaTransactions(projectId: number, page?: proto.Page): Promise<{ + page: proto.Page, + transactions: proto.MetaTxnLog[] + }> + + // getTransactionCost returns the used fee cost for gas tank during a given period + getTransactionCost(projectId: number, from: string, to: string): Promise<{ + cost: number + }> } export * from './local-relayer' diff --git a/packages/relayer/src/local-relayer.ts b/packages/relayer/src/local-relayer.ts index c0aacf899..9cf3a0acd 100644 --- a/packages/relayer/src/local-relayer.ts +++ b/packages/relayer/src/local-relayer.ts @@ -1,6 +1,6 @@ import { ethers } from 'ethers' import { logger } from '@0xsequence/utils' -import { FeeOption, FeeQuote, Relayer } from '.' +import { FeeOption, FeeQuote, proto, Relayer } from '.' import { ProviderRelayer, ProviderRelayerOptions } from './provider-relayer' import { commons } from '@0xsequence/core' @@ -76,6 +76,19 @@ export class LocalRelayer extends ProviderRelayer implements Relayer { return responsePromise } } + + async getMetaTransactions(projectId: number, page?: proto.Page): Promise<{ + page: proto.Page, + transactions: proto.MetaTxnLog[] + }> { + return { page: { page: 0, pageSize: 100 }, transactions: [] } + } + + async getTransactionCost(projectId: number, from: string, to: string): Promise<{ + cost: number + }> { + return { cost: 0 } + } } function isAbstractSigner(signer: any): signer is ethers.AbstractSigner { diff --git a/packages/relayer/src/provider-relayer.ts b/packages/relayer/src/provider-relayer.ts index 86652efe1..17800a921 100644 --- a/packages/relayer/src/provider-relayer.ts +++ b/packages/relayer/src/provider-relayer.ts @@ -1,6 +1,6 @@ import { ethers } from 'ethers' import { walletContracts } from '@0xsequence/abi' -import { FeeOption, FeeQuote, Relayer, SimulateResult } from '.' +import { FeeOption, FeeQuote, proto, Relayer, SimulateResult } from '.' import { logger, Optionals } from '@0xsequence/utils' import { commons } from '@0xsequence/core' @@ -59,6 +59,15 @@ export abstract class ProviderRelayer implements Relayer { waitForReceipt?: boolean ): Promise + abstract getTransactionCost(projectId: number, from: string, to: string): Promise<{ + cost: number + }> + + abstract getMetaTransactions(projectId: number, page?: proto.Page): Promise<{ + page: proto.Page, + transactions: proto.MetaTxnLog[] + }> + async simulate(wallet: string, ...transactions: commons.transaction.Transaction[]): Promise { return ( await Promise.all( @@ -248,6 +257,8 @@ export abstract class ProviderRelayer implements Relayer { return waitReceipt() } } + + } function isAbstractProvider(provider: any): provider is ethers.AbstractProvider { diff --git a/packages/relayer/src/rpc-relayer/index.ts b/packages/relayer/src/rpc-relayer/index.ts index 5b04a6893..bde372eb1 100644 --- a/packages/relayer/src/rpc-relayer/index.ts +++ b/packages/relayer/src/rpc-relayer/index.ts @@ -304,6 +304,19 @@ export class RpcRelayer implements Relayer { wait: async (confirmations?: number) => this.provider!.waitForTransaction(txReceipt.transactionHash, confirmations) } as commons.transaction.TransactionResponse } + + async getMetaTransactions(projectId: number, page?: proto.Page): Promise<{ + page: proto.Page, + transactions: proto.MetaTxnLog[] + }> { + return this.service.getMetaTransactions({ projectId, page }) + } + + async getTransactionCost(projectId: number, from: string, to: string): Promise<{ + cost: number + }> { + return this.service.getTransactionCost({ projectId, from, to }) + } } class MetaTransactionResponseException {