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

CompositeSyncOracle #515

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
Expand Up @@ -17,7 +17,7 @@ contract CompositeMultiOracle is IOracle, AccessControl {
mapping(bytes6 => mapping(bytes6 => IOracle)) public sources;
mapping(bytes6 => mapping(bytes6 => bytes6[])) public paths;

/// @notice Set or reset a Yearn Vault Token oracle source and its inverse
/// @notice Set or reset an oracle source and its inverse
/// @param baseId id used for underlying base token
/// @param quoteId id used for underlying quote token
/// @param source Oracle contract for source
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
// SPDX-License-Identifier: BUSL-1.1
pragma solidity >=0.8.13;

import { CompositeMultiOracle } from "./CompositeMultiOracle.sol";
import { ICauldron } from "../../interfaces/ICauldron.sol";
import "../../interfaces/DataTypes.sol";

/**
* @dev A CompositeMultiOracle that can take sources from a Cauldron.
*/
contract CompositeSyncOracle is CompositeMultiOracle {

event MasterSet(ICauldron indexed master);

ICauldron public master;

/// @notice Set the master
/// @param master_ ICauldron contract used as master
function setMaster(
ICauldron master_
) external auth {
master = master_;
emit MasterSet(master_);
}

/// @notice Copy an oracle source from the master. Only works if the source is not set yet.
/// @param baseId id used for underlying base token
/// @param quoteId id used for underlying quote token
function syncSource(
bytes6 baseId,
bytes6 quoteId
)
external
returns (IOracle source)
{
require(
sources[baseId][quoteId] == IOracle(address(0)) &&
sources[quoteId][baseId] == IOracle(address(0)),
"Only new sources"
);
require(master != ICauldron(address(0)), "Master not set");
DataTypes.SpotOracle memory spotOracle = master.spotOracles(baseId, quoteId);

source = spotOracle.oracle;
sources[baseId][quoteId] = source;
emit SourceSet(baseId, quoteId, source);

if (baseId != quoteId) {
sources[quoteId][baseId] = source;
emit SourceSet(quoteId, baseId, source);
}
}
}