diff --git a/packages/foundry/contracts/oracles/composite/CompositeMultiOracle.sol b/packages/foundry/contracts/oracles/composite/CompositeMultiOracle.sol index ff65ee5a1..5ea0d380c 100644 --- a/packages/foundry/contracts/oracles/composite/CompositeMultiOracle.sol +++ b/packages/foundry/contracts/oracles/composite/CompositeMultiOracle.sol @@ -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 diff --git a/packages/foundry/contracts/oracles/composite/CompositeSyncOracle.sol b/packages/foundry/contracts/oracles/composite/CompositeSyncOracle.sol new file mode 100644 index 000000000..a0ef10fb5 --- /dev/null +++ b/packages/foundry/contracts/oracles/composite/CompositeSyncOracle.sol @@ -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); + } + } +} diff --git a/packages/foundry/lib/forge-std b/packages/foundry/lib/forge-std index eb980e1d4..cd7d533f9 160000 --- a/packages/foundry/lib/forge-std +++ b/packages/foundry/lib/forge-std @@ -1 +1 @@ -Subproject commit eb980e1d4f0e8173ec27da77297ae411840c8ccb +Subproject commit cd7d533f9a0ee0ec02ad81e0a8f262bc4203c653