-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: Implement addtional fee estimation via resolvers
- Loading branch information
1 parent
17397b7
commit 0a87507
Showing
11 changed files
with
266 additions
and
85 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import pino from "pino"; | ||
import { JsonRpcProvider } from "ethers6"; | ||
import { ResolverConfig } from "./resolver"; | ||
import OPStackResolver from "./op-stack"; | ||
|
||
export const BASE_SEPOLIA_CHAIN_NAME = 'baseSepolia'; | ||
|
||
export class BaseSepoliaResolver extends OPStackResolver { | ||
|
||
constructor( | ||
config: ResolverConfig, | ||
provider: JsonRpcProvider, | ||
logger: pino.Logger, | ||
) { | ||
super( | ||
BASE_SEPOLIA_CHAIN_NAME, | ||
config, | ||
provider, | ||
logger, | ||
); | ||
} | ||
} | ||
|
||
export default BaseSepoliaResolver; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import { JsonRpcProvider, TransactionRequest } from "ethers6"; | ||
import { Resolver, ResolverConfig } from "./resolver"; | ||
import pino from "pino"; | ||
import { createPublicClient, http } from "viem"; | ||
import { publicActionsL2 } from 'viem/op-stack' | ||
|
||
export const RESOLVER_TYPE_OP_STACK = 'op-stack'; | ||
|
||
export class OPStackResolver extends Resolver { | ||
override readonly resolverType; | ||
|
||
private client: any; //TODO use VIEM types | ||
|
||
constructor( | ||
chainName: string, | ||
config: ResolverConfig, | ||
provider: JsonRpcProvider, | ||
logger: pino.Logger, | ||
) { | ||
super( | ||
config, | ||
provider, | ||
logger, | ||
); | ||
|
||
this.resolverType = RESOLVER_TYPE_OP_STACK; | ||
|
||
this.client = this.loadClient( | ||
chainName, | ||
this.provider._getConnection().url //TODO the 'rpc' url should be added to the ResolverConfig | ||
); | ||
} | ||
|
||
private loadClient( | ||
chainName: string, | ||
rpc: string, | ||
): any { | ||
// eslint-disable-next-line @typescript-eslint/no-var-requires | ||
const chain = require(`viem/chains`)[chainName]; | ||
|
||
return createPublicClient({ | ||
chain, | ||
transport: http(rpc), | ||
}).extend(publicActionsL2()); | ||
} | ||
|
||
override async estimateAdditionalFee( | ||
transactionRequest: TransactionRequest | ||
): Promise<bigint> { | ||
return this.client.estimateL1Fee(transactionRequest) | ||
} | ||
} | ||
|
||
export default OPStackResolver; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import pino from "pino"; | ||
import { JsonRpcProvider } from "ethers6"; | ||
import { ResolverConfig } from "./resolver"; | ||
import OPStackResolver from "./op-stack"; | ||
|
||
export const OPTIMISM_SEPOLIA_CHAIN_NAME = 'optimismSepolia'; | ||
|
||
export class OptimismSepoliaResolver extends OPStackResolver { | ||
|
||
constructor( | ||
config: ResolverConfig, | ||
provider: JsonRpcProvider, | ||
logger: pino.Logger, | ||
) { | ||
super( | ||
OPTIMISM_SEPOLIA_CHAIN_NAME, | ||
config, | ||
provider, | ||
logger, | ||
); | ||
} | ||
} | ||
|
||
export default OptimismSepoliaResolver; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.