Skip to content

Commit 2659187

Browse files
committed
fix proposal script for morpho wrapper init
1 parent 0f5fbb4 commit 2659187

File tree

3 files changed

+74
-110
lines changed

3 files changed

+74
-110
lines changed

proposals/mips/mip-x34/x34.sol

Lines changed: 60 additions & 92 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ contract x34 is HybridProposal, Configs, Networks {
4242
return BASE_FORK_ID;
4343
}
4444

45-
// Deploy new instances of ChainlinkOEVWrapper (core markets) and ChainlinkOEVMorphoWrapper (Morpho markets)
45+
// Deploy new instances of ChainlinkOEVWrapper (core markets) and ensure ChainlinkOEVMorphoWrapper implementation exists (Morpho)
4646
function deploy(Addresses addresses, address) public override {
4747
_deployCoreWrappers(addresses);
4848
_deployMorphoWrappers(addresses);
@@ -108,16 +108,66 @@ contract x34 is HybridProposal, Configs, Networks {
108108
_pushAction(
109109
proxyAdmin,
110110
abi.encodeWithSignature(
111-
"upgradeAndCall(address,address,bytes)",
111+
"upgrade(address,address)",
112112
addresses.getAddress(wrapperName),
113-
addresses.getAddress(MORPHO_IMPLEMENTATION_NAME),
114-
bytes("")
113+
addresses.getAddress(MORPHO_IMPLEMENTATION_NAME)
115114
),
116115
string.concat(
117-
"Upgrade Morpho OEV wrapper via upgradeAndCall for ",
116+
"Upgrade Morpho OEV wrapper via upgrade for ",
118117
morphoConfigs[i].oracleName
119118
)
120119
);
120+
121+
// Set storage for the new wrapper
122+
_pushAction(
123+
addresses.getAddress(wrapperName),
124+
abi.encodeWithSignature(
125+
"setFeeMultiplier(uint16)",
126+
FEE_MULTIPLIER
127+
),
128+
string.concat(
129+
"Set fee multiplier for ",
130+
morphoConfigs[i].oracleName
131+
)
132+
);
133+
134+
_pushAction(
135+
addresses.getAddress(wrapperName),
136+
abi.encodeWithSignature(
137+
"setMaxRoundDelay(uint256)",
138+
MAX_ROUND_DELAY
139+
),
140+
string.concat(
141+
"Set max round delay for ",
142+
morphoConfigs[i].oracleName
143+
)
144+
);
145+
146+
_pushAction(
147+
addresses.getAddress(wrapperName),
148+
abi.encodeWithSignature(
149+
"setMaxDecrements(uint256)",
150+
MAX_DECREMENTS
151+
),
152+
string.concat(
153+
"Set max decrements for ",
154+
morphoConfigs[i].oracleName
155+
)
156+
);
157+
158+
if (addresses.isAddressSet("OEV_WRAPPER_FEE_RECIPIENT")) {
159+
_pushAction(
160+
addresses.getAddress(wrapperName),
161+
abi.encodeWithSignature(
162+
"setFeeRecipient(address)",
163+
addresses.getAddress("OEV_WRAPPER_FEE_RECIPIENT")
164+
),
165+
string.concat(
166+
"Set fee recipient for ",
167+
morphoConfigs[i].oracleName
168+
)
169+
);
170+
}
121171
}
122172
}
123173

@@ -227,80 +277,18 @@ contract x34 is HybridProposal, Configs, Networks {
227277
vm.stopBroadcast();
228278
}
229279

230-
// FIX: only deploy one implementation and use for all proxies
231280
function _deployMorphoWrappers(Addresses addresses) internal {
232-
// If there are configured Morpho markets on this chain, deploy wrappers per market.
233-
// This is intentionally conservative: do nothing if core Morpho addresses are not set.
281+
// Only ensure implementation exists; do not deploy new proxies. We'll upgrade existing proxies instead.
234282
if (!addresses.isAddressSet("MORPHO_BLUE")) {
235283
return;
236284
}
237285

238-
address morphoBlue = addresses.getAddress("MORPHO_BLUE");
239-
240-
MorphoMarketConfig[]
241-
memory morphoConfigs = getMorphoMarketConfigurations(block.chainid);
242-
if (morphoConfigs.length == 0) {
243-
return;
244-
}
245-
246-
// Deploy or get the implementation contract
247-
ChainlinkOEVMorphoWrapper impl;
248286
if (!addresses.isAddressSet(MORPHO_IMPLEMENTATION_NAME)) {
249-
impl = new ChainlinkOEVMorphoWrapper();
287+
vm.startBroadcast();
288+
ChainlinkOEVMorphoWrapper impl = new ChainlinkOEVMorphoWrapper();
250289
addresses.addAddress(MORPHO_IMPLEMENTATION_NAME, address(impl));
251-
} else {
252-
impl = ChainlinkOEVMorphoWrapper(
253-
addresses.getAddress(MORPHO_IMPLEMENTATION_NAME)
254-
);
255-
}
256-
257-
vm.startBroadcast();
258-
259-
for (uint256 i = 0; i < morphoConfigs.length; i++) {
260-
string memory wrapperName = string(
261-
abi.encodePacked(morphoConfigs[i].oracleName, "_ORACLE_PROXY")
262-
);
263-
address proxyAdmin = addresses.getAddress(
264-
"CHAINLINK_ORACLE_PROXY_ADMIN"
265-
);
266-
address owner = addresses.getAddress("TEMPORAL_GOVERNOR");
267-
268-
// TODO: who should be the fee recipient?
269-
address feeRecipient = addresses.isAddressSet(
270-
"OEV_WRAPPER_FEE_RECIPIENT"
271-
)
272-
? addresses.getAddress("OEV_WRAPPER_FEE_RECIPIENT")
273-
: owner;
274-
275-
bytes memory initData = abi.encodeWithSelector(
276-
ChainlinkOEVMorphoWrapper.initialize.selector,
277-
addresses.getAddress(morphoConfigs[i].oracleName),
278-
owner,
279-
feeRecipient,
280-
FEE_MULTIPLIER,
281-
MAX_ROUND_DELAY,
282-
MAX_DECREMENTS,
283-
morphoBlue
284-
);
285-
286-
TransparentUpgradeableProxy proxy = new TransparentUpgradeableProxy(
287-
address(impl),
288-
proxyAdmin,
289-
initData
290-
);
291-
292-
// Set existing proxy to deprecated and add new proxy
293-
if (addresses.isAddressSet(wrapperName)) {
294-
addresses.addAddress(
295-
string(abi.encodePacked(wrapperName, "_DEPRECATED")),
296-
addresses.getAddress(wrapperName)
297-
);
298-
addresses.changeAddress(wrapperName, address(proxy), true);
299-
} else {
300-
addresses.addAddress(wrapperName, address(proxy));
301-
}
290+
vm.stopBroadcast();
302291
}
303-
vm.stopBroadcast();
304292
}
305293

306294
function _validateFeedsPointToWrappers(
@@ -378,23 +366,14 @@ contract x34 is HybridProposal, Configs, Networks {
378366
)
379367
);
380368
assertEq(
381-
address(wrapper.morphoBlue()),
369+
address(wrapper.MORPHO_BLUE()),
382370
morphoBlue,
383371
string.concat(
384372
"Morpho wrapper morphoBlue mismatch for ",
385373
wrapperName
386374
)
387375
);
388376

389-
// fee configs sane
390-
address feeRecipient = wrapper.feeRecipient();
391-
assertTrue(
392-
feeRecipient != address(0),
393-
string.concat(
394-
"Morpho wrapper feeRecipient zero for ",
395-
wrapperName
396-
)
397-
);
398377
assertEq(
399378
wrapper.feeMultiplier(),
400379
FEE_MULTIPLIER,
@@ -417,17 +396,6 @@ contract x34 is HybridProposal, Configs, Networks {
417396
)
418397
);
419398

420-
// cachedRoundId and latest data readable
421-
assertEq(
422-
wrapper.cachedRoundId(),
423-
AggregatorV3Interface(
424-
addresses.getAddress(morphoConfigs[i].oracleName)
425-
).latestRound(),
426-
string.concat(
427-
"Morpho wrapper cachedRoundId mismatch for ",
428-
wrapperName
429-
)
430-
);
431399
(uint80 roundId, int256 answer, , uint256 updatedAt, ) = wrapper
432400
.latestRoundData();
433401
assertGt(

src/oracles/ChainlinkOEVMorphoWrapper.sol

Lines changed: 13 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,10 @@ contract ChainlinkOEVMorphoWrapper is
2020
/// @notice The maximum basis points for the fee multiplier
2121
uint16 public constant MAX_BPS = 10000;
2222

23+
/// @notice The Morpho Blue contract address
24+
IMorphoBlue public constant MORPHO_BLUE =
25+
IMorphoBlue(0xBBBBBbbBBb9cC5e90e3b3Af64bdAF62C37EEFFCb);
26+
2327
/// @notice The Chainlink price feed this proxy forwards to
2428
AggregatorV3Interface public priceFeed;
2529

@@ -28,19 +32,16 @@ contract ChainlinkOEVMorphoWrapper is
2832

2933
/// @notice The fee multiplier for the OEV fees
3034
/// @dev Represented as a percentage
31-
uint16 public feeMultiplier;
35+
uint16 public feeMultiplier = 9900;
3236

3337
/// @notice The last cached round id
3438
uint256 public cachedRoundId;
3539

36-
/// @notice The max round delay
37-
uint256 public maxRoundDelay;
40+
/// @notice The max round delay (seconds)
41+
uint256 public maxRoundDelay = 10;
3842

3943
/// @notice The max decrements
40-
uint256 public maxDecrements;
41-
42-
/// @notice The Morpho Blue contract address
43-
IMorphoBlue public morphoBlue;
44+
uint256 public maxDecrements = 10;
4445

4546
/// @notice Emitted when the fee recipient is changed
4647
event FeeRecipientChanged(address oldFeeRecipient, address newFeeRecipient);
@@ -85,16 +86,14 @@ contract ChainlinkOEVMorphoWrapper is
8586
* @param _feeMultiplier The fee multiplier for the OEV fees
8687
* @param _maxRoundDelay The max round delay
8788
* @param _maxDecrements The max decrements
88-
* @param _morphoBlue Address of the Morpho Blue contract
8989
*/
9090
function initialize(
9191
address _priceFeed,
9292
address _owner,
9393
address _feeRecipient,
9494
uint16 _feeMultiplier,
9595
uint256 _maxRoundDelay,
96-
uint256 _maxDecrements,
97-
address _morphoBlue
96+
uint256 _maxDecrements
9897
) public initializer {
9998
require(
10099
_priceFeed != address(0),
@@ -120,17 +119,14 @@ contract ChainlinkOEVMorphoWrapper is
120119
_maxDecrements > 0,
121120
"ChainlinkOEVMorphoWrapper: max decrements cannot be zero"
122121
);
123-
require(
124-
_morphoBlue != address(0),
125-
"ChainlinkOEVMorphoWrapper: morpho blue cannot be zero address"
126-
);
127122
__Ownable_init();
128123

129124
priceFeed = AggregatorV3Interface(_priceFeed);
125+
feeRecipient = _feeRecipient;
126+
feeMultiplier = _feeMultiplier;
130127
cachedRoundId = priceFeed.latestRound();
131128
maxRoundDelay = _maxRoundDelay;
132129
maxDecrements = _maxDecrements;
133-
morphoBlue = IMorphoBlue(_morphoBlue);
134130

135131
_transferOwnership(_owner);
136132
}
@@ -396,13 +392,13 @@ contract ChainlinkOEVMorphoWrapper is
396392
loanToken.transferFrom(msg.sender, address(this), maxRepayAmount);
397393

398394
// approve Morpho Blue to spend the loan tokens
399-
loanToken.approve(address(morphoBlue), maxRepayAmount);
395+
loanToken.approve(address(MORPHO_BLUE), maxRepayAmount);
400396

401397
// liquidate the borrower on Morpho Blue
402398
// Morpho will: 1) Transfer seized collateral to this contract, 2) Pull loan tokens from this contract
403399
// seizedAssets: amount of collateral to seize
404400
// repaidShares: 0 (means we specify collateral amount, Morpho calculates debt repayment)
405-
(uint256 actualSeizedAssets, uint256 actualRepaidAssets) = morphoBlue
401+
(uint256 actualSeizedAssets, uint256 actualRepaidAssets) = MORPHO_BLUE
406402
.liquidate(marketParams, borrower, seizedAssets, 0, "");
407403

408404
// ensure actual repaid amount doesn't exceed liquidator's maximum

test/integration/oracle/ChainlinkOEVMorphoWrapperIntegration.t.sol

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -209,7 +209,7 @@ contract ChainlinkOEVMorphoWrapperIntegrationTest is
209209

210210
// Mock morpho.liquidate to return seized/repaid values
211211
vm.mockCall(
212-
address(wrapper.morphoBlue()),
212+
address(wrapper.MORPHO_BLUE()),
213213
abi.encodeWithSelector(
214214
IMorphoBlue.liquidate.selector,
215215
params,

0 commit comments

Comments
 (0)