Add scalar, decimals, getAllParams

This commit is contained in:
Andrew Morris
2023-05-09 10:21:48 +10:00
parent 5bd09ec4e5
commit 4fd11c0356

View File

@@ -8,11 +8,11 @@ export default class OptimismGasPriceOracle {
public provider: ethers.providers.Provider,
) {}
async l1BaseFee() {
private async callFn(method: string, blockTag?: ethers.providers.BlockTag) {
const outputBytes = await this.provider.call({
to: OptimismGasPriceOracle.address,
data: ethers.utils.id("l1BaseFee()"),
});
data: ethers.utils.id(method),
}, blockTag);
const result = ethers.utils.defaultAbiCoder.decode(
["uint256"],
@@ -24,19 +24,30 @@ export default class OptimismGasPriceOracle {
return result;
}
async overhead() {
const outputBytes = await this.provider.call({
to: OptimismGasPriceOracle.address,
data: ethers.utils.id("overhead()"),
});
async l1BaseFee(blockTag?: ethers.providers.BlockTag) {
return await this.callFn("l1BaseFee()", blockTag);
}
const result = ethers.utils.defaultAbiCoder.decode(
["uint256"],
outputBytes,
)[0];
async overhead(blockTag?: ethers.providers.BlockTag) {
return await this.callFn("overhead()", blockTag);
}
assert(result instanceof BigNumber);
async scalar(blockTag?: ethers.providers.BlockTag) {
return await this.callFn("scalar()", blockTag);
}
return result;
async decimals(blockTag?: ethers.providers.BlockTag) {
return await this.callFn("decimals()", blockTag);
}
async getAllParams(blockTag?: ethers.providers.BlockTag) {
const [l1BaseFee, overhead, scalar, decimals] = await Promise.all([
this.l1BaseFee(blockTag),
this.overhead(blockTag),
this.scalar(blockTag),
this.decimals(blockTag),
]);
return { l1BaseFee, overhead, scalar, decimals };
}
}