Skip to content

Commit

Permalink
OZ relayer actually gets speed from env (#628)
Browse files Browse the repository at this point in the history
* oz relayer speed actually propagated

* changeset add
  • Loading branch information
luketchang authored Nov 20, 2023
1 parent 2a0c971 commit b7febfc
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
5 changes: 5 additions & 0 deletions .changeset/fast-schools-allow.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"@nocturne-xyz/offchain-utils": patch
---

getting oz tx submitter from env propagates OZ_RELAYER_SPEED
18 changes: 14 additions & 4 deletions packages/offchain-utils/src/txSubmission.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@ export interface TxSubmissionArgs {
data: string;
}

export type TxSpeed = "safeLow" | "average" | "fast" | "fastest";

export interface TxSubmissionOpts {
value?: number;
gasLimit?: number;
speed?: "safeLow" | "average" | "fast" | "fastest";
speed?: TxSpeed;
isPrivate?: boolean;
numConfirmations?: number;
logger?: Logger;
Expand All @@ -37,6 +39,7 @@ export interface TxSubmitter {
export function getTxSubmitterFromEnv(): TxSubmitter {
const relayerApiKey = process.env.OZ_RELAYER_API_KEY;
const relayerApiSecret = process.env.OZ_RELAYER_API_SECRET;
const relayerSpeed = process.env.OZ_RELAYER_SPEED as TxSpeed | undefined;

const privateKey = process.env.TX_SIGNER_KEY;
const provider = getEthersProviderFromEnv();
Expand All @@ -51,7 +54,8 @@ export function getTxSubmitterFromEnv(): TxSubmitter {
keepAlive: true,
}),
});
return new OzRelayerTxSubmitter(relayer, provider);

return new OzRelayerTxSubmitter(relayer, provider, relayerSpeed);
} else if (privateKey) {
const signer = new ethers.Wallet(privateKey, provider);
return new EthersTxSubmitter(signer);
Expand Down Expand Up @@ -98,10 +102,16 @@ export class EthersTxSubmitter implements TxSubmitter {
export class OzRelayerTxSubmitter implements TxSubmitter {
provider: ethers.providers.JsonRpcProvider;
relayer: Relayer;
speed: TxSpeed;

constructor(relayer: Relayer, provider: ethers.providers.JsonRpcProvider) {
constructor(
relayer: Relayer,
provider: ethers.providers.JsonRpcProvider,
speed: TxSpeed = "fast"
) {
this.relayer = relayer;
this.provider = provider;
this.speed = speed;
}

async address(): Promise<Address> {
Expand All @@ -116,7 +126,7 @@ export class OzRelayerTxSubmitter implements TxSubmitter {
to,
data,
value: opts?.value ?? 0,
speed: opts?.speed ?? "fast",
speed: opts?.speed ?? this.speed,
gasLimit:
opts?.gasLimit ??
Number(
Expand Down

0 comments on commit b7febfc

Please sign in to comment.