Skip to content

Commit

Permalink
feat: setSendReceiveLib() (#27)
Browse files Browse the repository at this point in the history
* feat: ProxyAdmin => FraxProxyAdmin

* feat: setLibs
  • Loading branch information
pegahcarter authored Dec 10, 2024
1 parent b2c3c4c commit e9b64d1
Show file tree
Hide file tree
Showing 3 changed files with 86 additions and 18 deletions.
8 changes: 8 additions & 0 deletions contracts/FraxProxyAdmin.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.22;

import { ProxyAdmin } from "@fraxfinance/layerzero-v2-upgradeable/messagelib/contracts/upgradeable/proxy/ProxyAdmin.sol";

contract FraxProxyAdmin is ProxyAdmin {
constructor(address _admin) ProxyAdmin(_admin) {}
}
3 changes: 2 additions & 1 deletion scripts/BaseL0Script.sol
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { console } from "frax-std/FraxTest.sol";

import { SerializedTx, SafeTxUtil } from "scripts/SafeBatchSerialize.sol";
import { FraxOFTUpgradeable } from "contracts/FraxOFTUpgradeable.sol";
import { FraxProxyAdmin } from "contracts/FraxProxyAdmin.sol";
import { ImplementationMock } from "contracts/mocks/ImplementationMock.sol";

import { Ownable } from "@openzeppelin/contracts/access/Ownable.sol";
Expand Down Expand Up @@ -97,7 +98,7 @@ contract BaseL0Script is Script {
string public json;

function version() public virtual pure returns (uint256, uint256, uint256) {
return (1, 2, 0);
return (1, 2, 1);
}

modifier broadcastAs(uint256 privateKey) {
Expand Down
93 changes: 76 additions & 17 deletions scripts/DeployFraxOFTProtocol/DeployFraxOFTProtocol.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ contract DeployFraxOFTProtocol is BaseL0Script {
using Strings for uint256;

function version() public virtual override pure returns (uint256, uint256, uint256) {
return (1, 2, 0);
return (1, 2, 1);
}

function setUp() public virtual override {
Expand All @@ -41,15 +41,6 @@ contract DeployFraxOFTProtocol is BaseL0Script {
setupProxyDestinations();
}

function setupLegacyDestinations() public virtual {
for (uint256 i=0; i<legacyConfigs.length; i++) {
setupDestination({
_connectedConfig: legacyConfigs[i],
_connectedOfts: legacyOfts
});
}
}

function setupProxyDestinations() public virtual {
for (uint256 i=0; i<proxyConfigs.length; i++) {
// skip if destination == source
Expand All @@ -61,6 +52,10 @@ contract DeployFraxOFTProtocol is BaseL0Script {
}
}

function setupLegacyDestinations() public pure {
// DEPRECATED
}

function setupDestination(
L0Config memory _connectedConfig,
address[] memory _connectedOfts
Expand Down Expand Up @@ -88,12 +83,19 @@ contract DeployFraxOFTProtocol is BaseL0Script {
setupEvms();
setupNonEvms();

/// @dev configures legacy configs as well
setDVNs({
_connectedConfig: broadcastConfig,
_connectedOfts: proxyOfts,
_configs: allConfigs
});

setLibs({
_connectedConfig: broadcastConfig,
_connectedOfts: proxyOfts,
_configs: allConfigs
});

setPriviledgedRoles();
}

Expand All @@ -103,12 +105,6 @@ contract DeployFraxOFTProtocol is BaseL0Script {
_configs: evmConfigs
});

/// @dev legacy, non-upgradeable OFTs
setEvmPeers({
_connectedOfts: proxyOfts,
_peerOfts: legacyOfts,
_configs: legacyConfigs
});
/// @dev Upgradeable OFTs maintaining the same address cross-chain.
setEvmPeers({
_connectedOfts: proxyOfts,
Expand Down Expand Up @@ -160,7 +156,7 @@ contract DeployFraxOFTProtocol is BaseL0Script {
function deployFraxOFTUpgradeablesAndProxies() broadcastAs(oftDeployerPK) public virtual {

// Proxy admin (0x223a681fc5c5522c85C96157c0efA18cd6c5405c)
proxyAdmin = address(new ProxyAdmin(vm.addr(configDeployerPK)));
proxyAdmin = address(new FraxProxyAdmin(vm.addr(configDeployerPK)));

// Implementation mock (0x8f1B9c1fd67136D525E14D96Efb3887a33f16250)
implementationMock = address(new ImplementationMock());
Expand Down Expand Up @@ -503,4 +499,67 @@ contract DeployFraxOFTProtocol is BaseL0Script {
);
}
}

function setLibs(
L0Config memory _connectedConfig,
address[] memory _connectedOfts,
L0Config[] memory _configs
) public virtual {
// for each oft
for (uint256 o=0; o < _connectedOfts.length; o++) {
// for each destination
for (uint256 c=0; c < _configs.length; c++) {
setLib({
_connectedConfig: _connectedConfig,
_connectedOft: _connectedOfts[o],
_config: _configs[c]
});
}
}
}

function setLib(
L0Config memory _connectedConfig,
address _connectedOft,
L0Config memory _config
) public virtual {
// skip if the connected and target are the same
if (_connectedConfig.eid == _config.eid) return;

// set sendLib to default
bytes memory data = abi.encodeCall(
IMessageLibManager.setSendLibrary,
(
_connectedOft, uint32(_config.eid), _connectedConfig.sendLib302
)
);
(bool success,) = _connectedConfig.endpoint.call(data);
require(success, "Unable to call setSendLibrary");
serializedTxs.push(
SerializedTx({
name: "setSendLibrary",
to: _connectedConfig.endpoint,
value: 0,
data: data
})
);

// set receiveLib to default
data = abi.encodeCall(
IMessageLibManager.setReceiveLibrary,
(
_connectedOft, uint32(_config.eid), _connectedConfig.receiveLib302, 0
)
);
(success,) = _connectedConfig.endpoint.call(data);
require(success, "Unable to call setReceiveLibrary");
serializedTxs.push(
SerializedTx({
name: "setReceiveLibrary",
to: _connectedConfig.endpoint,
value: 0,
data: data
})
);
}
}

0 comments on commit e9b64d1

Please sign in to comment.