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

feat: add fixedPriceOracle #102

Merged
merged 2 commits into from
Apr 15, 2024
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
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//SPDX-License-Identifier: MIT
pragma solidity ^0.8.17;
import "./IPriceOracle.sol";

contract FixedPriceOracle is IPriceOracle {
uint256 public constant FIXED_PRICE_USD = 1000000 * 10 ** 18; // 1,000,000 USD in Wei

function price(
string calldata,
uint256,
uint256
) external pure override returns (Price memory) {
return Price(FIXED_PRICE_USD, 0);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,6 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
'BaseRegistrarImplementation',
owner,
)
const priceOracle = await ethers.getContract(
'ExponentialPremiumPriceOracle',
owner,
)
const reverseRegistrar = await ethers.getContract('ReverseRegistrar', owner)
const nameWrapper = await ethers.getContract('NameWrapper', owner)
const ethOwnedResolver = await ethers.getContract('OwnedResolver', owner)
Expand All @@ -38,17 +34,26 @@ const func: DeployFunction = async function (hre: HardhatRuntimeEnvironment) {
log: true,
})

// Ensure the deployment was successful before proceeding
if (!pohVerifierDeployment.newlyDeployed) {
console.error('Failed to deploy PohVerifier')
// Deploy the FixedPriceOracle contract
const fixedPriceOracleDeployment = await deploy('FixedPriceOracle', {
from: owner,
log: true,
})

// Ensure the deployments were successful before proceeding
if (
!pohVerifierDeployment.newlyDeployed ||
!fixedPriceOracleDeployment.newlyDeployed
) {
console.error('Failed to deploy PohVerifier or FixedPriceOracle')
return
}

const deployArgs = {
from: deployer,
args: [
registrar.address,
priceOracle.address,
fixedPriceOracleDeployment.address, // Pass the FixedPriceOracle address
60,
86400,
reverseRegistrar.address,
Expand Down Expand Up @@ -118,7 +123,6 @@ func.tags = ['ethregistrar', 'ETHRegistrarController']
func.dependencies = [
'ENSRegistry',
'BaseRegistrarImplementation',
'ExponentialPremiumPriceOracle',
'ReverseRegistrar',
'NameWrapper',
'OwnedResolver',
Expand Down
51 changes: 51 additions & 0 deletions packages/l2-contracts/test/ethregistrar/TestFixedPriceOracle.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
const { expect } = require('chai');
const { ethers } = require('hardhat');

describe('FixedPriceOracle', function () {
let FixedPriceOracle;
let fixedPriceOracle;

beforeEach(async function () {
FixedPriceOracle = await ethers.getContractFactory('FixedPriceOracle');
fixedPriceOracle = await FixedPriceOracle.deploy();
await fixedPriceOracle.deployed();
});

it('should return the fixed price in USD', async function () {
const fixedPriceUSD = await fixedPriceOracle.FIXED_PRICE_USD();
const expectedFixedPriceUSD = ethers.utils.parseEther('1000000');

expect(fixedPriceUSD).to.equal(expectedFixedPriceUSD);
});

it('should return the fixed price for any input parameters', async function () {
const name = 'example.linea-test.eth';
const expires = 0;
const duration = 31536000; // 1 year in seconds

const price = await fixedPriceOracle.price(name, expires, duration);

expect(price.base).to.equal(ethers.utils.parseEther('1000000'));
expect(price.premium).to.equal(0);
});

it('should return the fixed price for different input parameters', async function () {
const name1 = 'test.linea-test.eth';
const expires1 = 1234567890;
const duration1 = 2592000; // 30 days in seconds

const price1 = await fixedPriceOracle.price(name1, expires1, duration1);

expect(price1.base).to.equal(ethers.utils.parseEther('1000000'));
expect(price1.premium).to.equal(0);

const name2 = 'another.linea-test.eth';
const expires2 = 9876543210;
const duration2 = 31536000; // 1 year in seconds

const price2 = await fixedPriceOracle.price(name2, expires2, duration2);

expect(price2.base).to.equal(ethers.utils.parseEther('1000000'));
expect(price2.premium).to.equal(0);
});
});
Loading