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

Extract new relayer endpoints #643

Merged
merged 7 commits into from
Jan 14, 2025
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
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
Loading