Skip to content

Commit

Permalink
Merge pull request #436 from equilibria-xyz/arjun/pe-1709
Browse files Browse the repository at this point in the history
Add string 'factoryType' to IKeeperFactory and impls
  • Loading branch information
arjun-io authored Oct 16, 2024
2 parents 4410115 + 4e82543 commit 868e010
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import "../keeper/KeeperFactory.sol";
/// @notice Factory contract for creating and managing Chainlink oracles
contract ChainlinkFactory is IChainlinkFactory, KeeperFactory {
uint256 private constant PERCENTAGE_SCALAR = 1e18;
string public constant factoryType = "ChainlinkFactory";

/// @dev Chainlink verifier contract
IVerifierProxy public immutable chainlink;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ interface IKeeperFactory is IOracleProviderFactory, IFactory {
error KeeperFactoryVersionOutsideRangeError();

function initialize(IOracleFactory oracleFactory) external;
function factoryType() external view returns (string memory);
function commitmentGasOracle() external view returns (IGasOracle);
function settlementGasOracle() external view returns (IGasOracle);
function updateId(IOracleProvider oracleProvider, bytes32 oracleId) external;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,31 @@ contract MetaQuantsFactory is IMetaQuantsFactory, KeeperFactory {

address public immutable signer;

bytes32 private immutable _factoryType;

constructor(
address signer_,
IGasOracle commitmentGasOracle_,
IGasOracle settlementGasOracle_,
string memory factoryType_,
address implementation_
) KeeperFactory(commitmentGasOracle_, settlementGasOracle_, implementation_) {
signer = signer_;
bytes memory bstr = bytes(factoryType_);
_factoryType = bytes32(uint256(bytes32(bstr)) | bstr.length);
}

/// @dev Uses's OZ's short string storage util (only available in newer versions of oz/contracts)
/// https://github.com/OpenZeppelin/openzeppelin-contracts/blob/master/contracts/utils/ShortStrings.sol
function factoryType() external view returns (string memory) {
bytes32 shortString = _factoryType;
uint256 len = uint256(_factoryType) & 0xFF;
string memory str = new string(32);
assembly ("memory-safe") {
mstore(str, len)
mstore(add(str, 0x20), shortString)
}
return str;
}

/// @notice Validates and parses the update data payload against the specified version
Expand Down
1 change: 1 addition & 0 deletions packages/perennial-oracle/contracts/pyth/PythFactory.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import "../keeper/KeeperFactory.sol";
/// @notice Factory contract for creating and managing Pyth oracles
contract PythFactory is IPythFactory, KeeperFactory {
int32 private constant PARSE_DECIMALS = 18;
string public constant factoryType = "PythFactory";

/// @dev Pyth contract
AbstractPyth public immutable pyth;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,7 @@ testOracles.forEach(testOracle => {
SIGNER,
commitmentGasOracle.address,
settlementGasOracle.address,
'SignedPriceFactory',
keeperOracleImpl.address,
)
await metaquantsOracleFactory.initialize(oracleFactory.address)
Expand Down Expand Up @@ -469,12 +470,17 @@ testOracles.forEach(testOracle => {
})

describe('Factory', async () => {
it('factoryType is set', async () => {
expect(await metaquantsOracleFactory.factoryType()).to.equal('SignedPriceFactory')
})

context('#initialize', async () => {
it('reverts if already initialized', async () => {
const metaquantsOracleFactory2 = await new MetaQuantsFactory__factory(owner).deploy(
SIGNER,
commitmentGasOracle.address,
settlementGasOracle.address,
'SignedPriceFactory',
await metaquantsOracleFactory.implementation(),
)
await metaquantsOracleFactory2.initialize(oracleFactory.address)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,10 @@ describe('ChainlinkFactory', () => {
oracleSigner = await impersonateWithBalance(oracle.address, utils.parseEther('10'))
})

it('factoryType is ChainlinkFactory', async () => {
expect(await chainlinkFactory.factoryType()).to.equal('ChainlinkFactory')
})

it('parses Chainlink report correctly', async () => {
market.claimFee.returns(utils.parseUnits('0.25', 6))
await keeperOracle.connect(oracleSigner).request(market.address, user.address)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,10 @@ describe('PythOracleFactory', () => {
oracleSigner = await impersonateWithBalance(oracle.address, utils.parseEther('10'))
})

it('factoryType is PythFactory', async () => {
expect(await pythOracleFactory.factoryType()).to.equal('PythFactory')
})

it('parses Pyth exponents correctly', async () => {
market.claimFee.returns(utils.parseUnits('0.25', 6))

Expand Down

0 comments on commit 868e010

Please sign in to comment.