Skip to content

Commit

Permalink
Merge branch 'woof-software/update-pricefeeds-for-rseth-and-weeth-on-…
Browse files Browse the repository at this point in the history
…mainnet-weth' of github.com:woof-software/comet into woof-software/add-ezETH-to-weth-mainnet
  • Loading branch information
MishaShWoof committed Jul 8, 2024
2 parents b18c7e0 + 563f2ba commit e0706a1
Show file tree
Hide file tree
Showing 4 changed files with 130 additions and 10 deletions.
14 changes: 12 additions & 2 deletions contracts/pricefeeds/RateBasedScalingPriceFeed.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,10 @@ import "../IRateProvider.sol";
contract RateBasedScalingPriceFeed is IPriceFeed {
/** Custom errors **/
error InvalidInt256();
error BadDecimals();

/// @notice Version of the price feed
uint public constant override version = 1;
uint public constant VERSION = 1;

/// @notice Description of the price feed
string public description;
Expand All @@ -39,6 +40,7 @@ contract RateBasedScalingPriceFeed is IPriceFeed {
**/
constructor(address underlyingPriceFeed_, uint8 decimals_, uint8 underlyingDecimals_, string memory description_) {
underlyingPriceFeed = underlyingPriceFeed_;
if (decimals_ > 18) revert BadDecimals();
decimals = decimals_;
description = description_;

Expand Down Expand Up @@ -67,7 +69,7 @@ contract RateBasedScalingPriceFeed is IPriceFeed {
uint80 answeredInRound
) {
uint256 rate = IRateProvider(underlyingPriceFeed).getRate();

Check warning

Code scanning / Semgrep OSS

IRateProvider(underlyingPriceFeed).getRate() call on a Balancer pool is not protected from the read-only reentrancy. Warning

IRateProvider(underlyingPriceFeed).getRate() call on a Balancer pool is not protected from the read-only reentrancy.
return (roundId, scalePrice(int256(rate)), startedAt, updatedAt, answeredInRound);
return (1, scalePrice(signed256(rate)), block.timestamp, block.timestamp, 1);
}

function signed256(uint256 n) internal pure returns (int256) {
Expand All @@ -84,4 +86,12 @@ contract RateBasedScalingPriceFeed is IPriceFeed {
}
return scaledPrice;
}

/**
* @notice Current version of the price feed
* @return The version of the price feed contract
**/
function version() external pure returns (uint256) {
return VERSION;
}
}
18 changes: 14 additions & 4 deletions contracts/pricefeeds/RsETHScalingPriceFeed.sol
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,13 @@ import "../IPriceFeed.sol";
* @notice A custom price feed that scales up or down the price received from an underlying Kelp price feed and returns the result
* @author Compound
*/
contract rsETHScalingPriceFeed is IPriceFeed {
contract RsETHScalingPriceFeed is IPriceFeed {
/** Custom errors **/
error InvalidInt256();
error BadDecimals();

/// @notice Version of the price feed
uint public constant override version = 1;
uint public constant VERSION = 1;

/// @notice Description of the price feed
string public description;
Expand All @@ -39,6 +40,7 @@ contract rsETHScalingPriceFeed is IPriceFeed {
**/
constructor(address underlyingPriceFeed_, uint8 decimals_, string memory description_) {
underlyingPriceFeed = underlyingPriceFeed_;
if (decimals_ > 18) revert BadDecimals();
decimals = decimals_;
description = description_;

Expand Down Expand Up @@ -66,8 +68,8 @@ contract rsETHScalingPriceFeed is IPriceFeed {
uint256 updatedAt,
uint80 answeredInRound
) {
int256 price = int256(ILRTOracle(underlyingPriceFeed).rsETHPrice());
return (roundId, scalePrice(price), startedAt, updatedAt, answeredInRound);
int256 price = signed256(ILRTOracle(underlyingPriceFeed).rsETHPrice());
return (1, scalePrice(price), block.timestamp, block.timestamp, 1);
}

function signed256(uint256 n) internal pure returns (int256) {
Expand All @@ -84,4 +86,12 @@ contract rsETHScalingPriceFeed is IPriceFeed {
}
return scaledPrice;
}

/**
* @notice Current version of the price feed
* @return The version of the price feed contract
**/
function version() external pure returns (uint256) {
return VERSION;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
import { DeploymentManager, migration } from '../../../../plugins/deployment_manager';
import { proposal } from '../../../../src/deploy';

import { expect } from 'chai';
import { ethers } from 'ethers';

const RSETH_ADDRESS = '0xA1290d69c65A6Fe4DF752f95823fae25cB99e5A7';
const RSETH_PRICEFEED_ADDRESS = '0x349A73444b1a310BAe67ef67973022020d70020d';
const WEETH_ADDRESS = '0xCd5fE23C85820F7B72D0926FC9b05b43E359b7ee';
const WEETH_PRICEFEED_ADDRESS = '0xCd5fE23C85820F7B72D0926FC9b05b43E359b7ee';

let newRsETHPriceFeed: string;
let newWeETHPriceFeed: string;

export default migration('1719835184_update_rseth_and_weth_pricefeed', {
async prepare(deploymentManager: DeploymentManager) {
const _rsETHPriceFeed = await deploymentManager.deploy(
'rsETH:priceFeed',
'pricefeeds/RsETHScalingPriceFeed.sol',
[RSETH_PRICEFEED_ADDRESS, 8, 'rsETH / ETH exchange rate']
);

const _weETHPriceFeed = await deploymentManager.deploy(
'weETH:priceFeed',
'pricefeeds/RateBasedScalingPriceFeed.sol',
[WEETH_PRICEFEED_ADDRESS, 8, 18, 'weETH / ETH exchange rate']
);
return { rsETHPriceFeed: _rsETHPriceFeed.address, weETHPriceFeed: _weETHPriceFeed.address};
},

async enact(deploymentManager: DeploymentManager, _, { rsETHPriceFeed, weETHPriceFeed }) {
const trace = deploymentManager.tracer();

const {
governor,
comet,
configurator,
cometAdmin,
} = await deploymentManager.getContracts();

newRsETHPriceFeed = rsETHPriceFeed;
newWeETHPriceFeed = weETHPriceFeed;
const actions = [
// 1. Update the price feed for rsETH
{
contract: configurator,
signature: 'updateAssetPriceFeed(address,address,address)',
args: [comet.address, RSETH_ADDRESS, rsETHPriceFeed],
},
// 2. Update the price feed for weETH
{
contract: configurator,
signature: 'updateAssetPriceFeed(address,address,address)',
args: [comet.address, WEETH_ADDRESS, weETHPriceFeed],
},
// 3. Deploy and upgrade to a new version of Comet
{
contract: cometAdmin,
signature: 'deployAndUpgradeTo(address,address)',
args: [configurator.address, comet.address],
},
];
const description = '# Update rsETH and weETH price feeds in cWETHv3 on Mainnet\n\n## Proposal summary\n\nThis proposal updates existing price feeds for rsETH and weETH collaterals in the WETH market on Mainnet from market rates to exchange rates. If exchange rate oracles are implemented, Gauntlet can recommend more capital efficient parameters as the asset remains insulated from market movements, although this exposes it to tail-end risks. The exchange rate based risk parameters could facilitate higher caps and Liquidation Factors along with more conservative Liquidation Penalties.\n\nFurther detailed information can be found on the corresponding [proposal pull request](https://github.com/compound-finance/comet/pull/878), [forum discussion for rsETH](https://www.comp.xyz/t/add-rseth-market-on-ethereum-mainnet/5118) and [forum discussion for weETH](https://www.comp.xyz/t/add-weeth-market-on-ethereum/5179).\n\n\n## Proposal Actions\n\nThe first proposal action updates rsETH price feed from market rate to exchange rate.\n\nThe second proposal action updates weETH price feed from market rate to exchange rate.\n\nThe third action deploys and upgrades Comet to a new version.';
const txn = await deploymentManager.retry(
async () => trace((await governor.propose(...await proposal(actions, description))))
);

const event = txn.events.find(event => event.event === 'ProposalCreated');
const [proposalId] = event.args;

trace(`Created proposal ${proposalId}.`);
},

async enacted(): Promise<boolean> {
return false;
},

async verify(deploymentManager: DeploymentManager) {
const {
comet,
configurator
} = await deploymentManager.getContracts();

const rsETH = new ethers.Contract(RSETH_ADDRESS, [
'function symbol() view returns (string)',
], deploymentManager.hre.ethers.provider);

const weETH = new ethers.Contract(WEETH_ADDRESS, [
'function symbol() view returns (string)',
], deploymentManager.hre.ethers.provider);

expect(await rsETH.symbol()).to.eq('rsETH');
const rsETHId = await configurator.getAssetIndex(comet.address, RSETH_ADDRESS);
expect(await weETH.symbol()).to.eq('weETH');
const weETHId = await configurator.getAssetIndex(comet.address, WEETH_ADDRESS);
const configuration = await configurator.getConfiguration(comet.address);
expect(configuration.assetConfigs[rsETHId].priceFeed).to.eq(newRsETHPriceFeed);
expect(configuration.assetConfigs[weETHId].priceFeed).to.eq(newWeETHPriceFeed);
},
});
8 changes: 4 additions & 4 deletions deployments/mainnet/weth/relations.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,16 @@ export default {
artifact: 'contracts/ERC20.sol:ERC20',
delegates: {
field: {
slot: '0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc'
slot: '0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc',
}
}
},
},
'TransparentUpgradeableProxy': {
artifact: 'contracts/ERC20.sol:ERC20',
delegates: {
field: {
slot: '0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc'
slot: '0x360894a13ba1a3210667c828492db98dca3e2076cc3735a920a3ca505d382bbc',
}
}
},
},
};

0 comments on commit e0706a1

Please sign in to comment.