Skip to content

Commit

Permalink
feat: update deploy script accord to contract changes
Browse files Browse the repository at this point in the history
  • Loading branch information
simonzg committed Jul 8, 2024
1 parent 0e429bc commit 1682d0c
Show file tree
Hide file tree
Showing 7 changed files with 46 additions and 39 deletions.
2 changes: 1 addition & 1 deletion contracts/ResilientOracle.sol
Original file line number Diff line number Diff line change
Expand Up @@ -452,7 +452,7 @@ contract ResilientOracle is PausableUpgradeable, AccessControlledV8, ResilientOr
* @return asset underlying asset address
*/
function _getUnderlyingAsset(address vToken) private view notNullAddress(vToken) returns (address asset) {
if (vToken == nativeMarket && VBep20Interface(vToken).isCEther()) {
if (vToken == nativeMarket) {
asset = nativeAsset;
} else {
asset = VBep20Interface(vToken).underlying();
Expand Down
2 changes: 0 additions & 2 deletions contracts/interfaces/VBep20Interface.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,4 @@ interface VBep20Interface is IERC20Metadata {
* @notice Underlying asset for this VToken
*/
function underlying() external view returns (address);

function isCEther() external view returns (bool);
}
30 changes: 3 additions & 27 deletions contracts/oracles/PendleOracle.sol
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,6 @@ contract PendleOracle is AccessControlledV8, OracleInterface {

OracleInterface public intermediateOracle;

address public underlyingAsset;

/// @notice Token config by assets
mapping(address => TokenConfig) public tokenConfigs;

Expand Down Expand Up @@ -65,23 +63,14 @@ contract PendleOracle is AccessControlledV8, OracleInterface {
* @notice Initializes the owner of the contract
* @param accessControlManager_ Address of the access control manager contract
*/
function initialize(
address accessControlManager_,
address ptOracle,
address underlyingAsset_,
address resilientOracle
) external initializer {
function initialize(address accessControlManager_, address ptOracle, address resilientOracle) external initializer {
__AccessControlled_init(accessControlManager_);
ensureNonzeroAddress(ptOracle);
ensureNonzeroAddress(resilientOracle);
ensureNonzeroAddress(underlyingAsset_);

underlyingPtOracle = IPendlePtOracle(ptOracle);
emit PtOracleSet(address(0), address(underlyingPtOracle));

underlyingAsset = underlyingAsset_;
emit UnderlyingAssetSet(address(0), underlyingAsset);

intermediateOracle = OracleInterface(resilientOracle);
emit IntermediateOracleSet(address(0), address(intermediateOracle));
}
Expand Down Expand Up @@ -135,20 +124,6 @@ contract PendleOracle is AccessControlledV8, OracleInterface {
emit IntermediateOracleSet(address(oldOracle), address(intermediateOracle_));
}

/**
* @notice Set the underlying sset contract address
* @param underlyingAsset_ underlying asset contract address
* @custom:access Only Governance
* @custom:error NotNullAddress error thrown if intermediateOracle_ address is zero
* @custom:event Emits IntermediateOracleSet event with address of Pyth oracle.
*/
function setUnderlyingAsset(address underlyingAsset_) external notNullAddress(address(underlyingAsset_)) {
_checkAccessAllowed("setUnderlyingAsset(address)");
address oldAddress = underlyingAsset;
underlyingAsset = underlyingAsset_;
emit UnderlyingAssetSet(address(oldAddress), address(underlyingAsset_));
}

/**
* @notice Add single token config. asset & feed cannot be null addresses and maxStalePeriod must be positive
* @param tokenConfig Token config struct
Expand Down Expand Up @@ -191,6 +166,7 @@ contract PendleOracle is AccessControlledV8, OracleInterface {
if (tokenConfig.asset != asset) revert("unknown token");
uint256 rate = underlyingPtOracle.getPtToSyRate(tokenConfig.market, tokenConfig.twapDuration);

return (intermediateOracle.getPrice(underlyingAsset) * rate) / EXP_SCALE;
(IStandardizedYield sy, , ) = IPMarket(tokenConfig.market).readTokens();
return (intermediateOracle.getPrice(sy.yieldToken()) * rate) / EXP_SCALE;
}
}
29 changes: 29 additions & 0 deletions contracts/oracles/WstETHOracle.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// SPDX-License-Identifier: BSD-3-Clause
pragma solidity 0.8.25;

import { IStETH } from "../interfaces/IStETH.sol";
import { CorrelatedTokenOracle } from "./common/CorrelatedTokenOracle.sol";
import { EXP_SCALE } from "@venusprotocol/solidity-utilities/contracts/constants.sol";

/**
* @title WstETHOracle renamed from WstETHOracleV2 in venus
* @author Venus
* @notice This oracle fetches the price of wstETH
*/
contract WstETHOracle is CorrelatedTokenOracle {
/// @notice Constructor for the implementation contract.
/// @custom:oz-upgrades-unsafe-allow constructor
constructor(
address wstETH,
address stETH,
address resilientOracle
) CorrelatedTokenOracle(wstETH, stETH, resilientOracle) {}

/**
* @notice Gets the stETH for 1 wstETH
* @return amount Amount of stETH
*/
function _getUnderlyingAmount() internal view override returns (uint256) {
return IStETH(UNDERLYING_TOKEN).getPooledEthByShares(EXP_SCALE);
}
}
4 changes: 2 additions & 2 deletions contracts/oracles/common/CorrelatedTokenOracle.sol
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,8 @@ abstract contract CorrelatedTokenOracle is OracleInterface {
// oracle returns (36 - asset decimal) scaled price
uint256 underlyingUSDPrice = RESILIENT_ORACLE.getPrice(UNDERLYING_TOKEN);

IERC20Metadata token = IERC20Metadata(CORRELATED_TOKEN);
uint256 decimals = token.decimals();
// IERC20Metadata token = IERC20Metadata(CORRELATED_TOKEN);
// uint256 decimals = token.decimals();

// underlyingAmount (for 1 correlated token) * underlyingUSDPrice / decimals(correlated token)
return (underlyingAmount * underlyingUSDPrice) / EXP_SCALE;
Expand Down
16 changes: 10 additions & 6 deletions deploy/1-deploy-oracles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const func: DeployFunction = async function ({ getNamedAccounts, deployments, ne

console.log(`Timelock: ${ADDRESSES[networkName].timelock}`);

const { nativeAsset } = ADDRESSES[networkName];
const { nativeMarket, nativeAsset } = ADDRESSES[networkName];

if (!ADDRESSES[networkName].acm || ADDRESSES[networkName].acm === ethers.constants.AddressZero) {
await deploy("AccessControlManager", {
Expand All @@ -57,8 +57,11 @@ const func: DeployFunction = async function ({ getNamedAccounts, deployments, ne
});
}

if (!nativeMarket) {
throw new Error("nativeMarket must NOT be empty");
}
if (!nativeAsset) {
throw new Error("nativeAsset must NOT empty");
throw new Error("nativeAsset must NOT be empty");
}

const accessControlManager = await hre.ethers.getContract("AccessControlManager");
Expand Down Expand Up @@ -96,7 +99,7 @@ const func: DeployFunction = async function ({ getNamedAccounts, deployments, ne
from: deployer,
log: true,
deterministicDeployment: false,
args: [nativeAsset, boundValidator.address],
args: [nativeMarket, nativeAsset, boundValidator.address],
proxy: {
owner: proxyOwnerAddress,
proxyContract: "OptimizedTransparentProxy",
Expand Down Expand Up @@ -172,11 +175,11 @@ const func: DeployFunction = async function ({ getNamedAccounts, deployments, ne
});
}

const { ptOracle, weETH } = ADDRESSES[networkName];
const { ptOracle } = ADDRESSES[networkName];
const resilientOracle = await hre.ethers.getContract("ResilientOracle");

// Skip if no ptOracle address in config
if (ptOracle && weETH) {
if (ptOracle) {
await deploy("PendleOracle", {
contract: "PendleOracle",
from: deployer,
Expand All @@ -189,13 +192,14 @@ const func: DeployFunction = async function ({ getNamedAccounts, deployments, ne
execute: {
init: {
methodName: "initialize",
args: [accessControlManagerAddress, ptOracle, weETH, resilientOracle.address],
args: [accessControlManagerAddress, ptOracle, resilientOracle.address],
},
},
},
});
}

// deploy OneJumpOracle for token with `denominatedBy` field in asset
for (const asset of assets[networkName]) {
if (asset.denominatedBy) {
if (!(asset.denominatedBy in ADDRESSES[networkName])) {
Expand Down
2 changes: 1 addition & 1 deletion deploy/6-configure-main-feeds.ts
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ const configurePriceFeeds = async (hre: HardhatRuntimeEnvironment): Promise<void
}
} else if (oracle === "pendle") {
const oracleContract = await hre.ethers.getContractAt(
"PendleOracle",
`PendleOracle`,
oraclesData[oracle].underlyingOracle.address,
);
const configOnChain = await oracleContract.tokenConfigs(tokenConfig.asset);
Expand Down

0 comments on commit 1682d0c

Please sign in to comment.