Skip to content

Commit

Permalink
Extract new relayer endpoints (#643)
Browse files Browse the repository at this point in the history
* Extract new relayer endpoints

* Update comment

* Add local relayer

* Update provider relayer

* Fix ts issues

* Update

* Update
  • Loading branch information
yigiterdev authored Jan 14, 2025
1 parent 7a3e55a commit fcf4fef
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 2 deletions.
11 changes: 11 additions & 0 deletions packages/relayer/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,17 @@ export interface Relayer {
delay?: number,
maxFails?: number
): Promise<commons.transaction.TransactionResponse>

// 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'
Expand Down
15 changes: 14 additions & 1 deletion packages/relayer/src/local-relayer.ts
Original file line number Diff line number Diff line change
@@ -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'

Expand Down Expand Up @@ -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 {
Expand Down
13 changes: 12 additions & 1 deletion packages/relayer/src/provider-relayer.ts
Original file line number Diff line number Diff line change
@@ -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'

Expand Down Expand Up @@ -59,6 +59,15 @@ export abstract class ProviderRelayer implements Relayer {
waitForReceipt?: boolean
): Promise<commons.transaction.TransactionResponse>

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<SimulateResult[]> {
return (
await Promise.all(
Expand Down Expand Up @@ -248,6 +257,8 @@ export abstract class ProviderRelayer implements Relayer {
return waitReceipt()
}
}


}

function isAbstractProvider(provider: any): provider is ethers.AbstractProvider {
Expand Down
13 changes: 13 additions & 0 deletions packages/relayer/src/rpc-relayer/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down

0 comments on commit fcf4fef

Please sign in to comment.