Skip to content

Commit

Permalink
feat: added ethereum
Browse files Browse the repository at this point in the history
  • Loading branch information
sendra committed Mar 6, 2024
1 parent 9322807 commit fc4d295
Show file tree
Hide file tree
Showing 6 changed files with 647 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,58 +27,93 @@ contract AaveV3Avalanche_ADIAndBridgeAdaptersUpdate_20240305 is IProposalGeneric
address public constant DESTINATION_HL_NEW_ADAPTER = address(0); // TODO: change for real address when deployed in ethereum
address public constant NEW_CROSS_CHAIN_CONTROLLER_IMPLEMENTATION = address(0); // TODO: change for real address when deployed

function execute() external {
// Update CrossChainController implementation
ProxyAdmin(MiscAvalanche.PROXY_ADMIN).upgradeAndCall(
TransparentUpgradeableProxy(payable(GovernanceV3Avalanche.CROSS_CHAIN_CONTROLLER)),
NEW_CROSS_CHAIN_CONTROLLER_IMPLEMENTATION,
abi.encodeWithSignature('initializeRevision()')
);

// Set new Receiver bridge adapter
function _getReceiverBridgeAdaptersToRemove()
internal
pure
returns (ICrossChainReceiver.ReceiverBridgeAdapterConfigInput[] memory)
{
uint256[] memory chainIds = new uint256[](1);
chainIds[0] = ChainIds.MAINNET;

// remove old Receiver bridge adapter
ICrossChainReceiver.ReceiverBridgeAdapterConfigInput[]
memory bridgeAdapterConfig = new ICrossChainReceiver.ReceiverBridgeAdapterConfigInput[](3);
memory bridgeAdaptersToRemove = new ICrossChainReceiver.ReceiverBridgeAdapterConfigInput[](3);

bridgeAdapterConfig[0] = ICrossChainReceiver.ReceiverBridgeAdapterConfigInput({
bridgeAdapter: CCIP_NEW_ADAPTER,
bridgeAdaptersToRemove[0] = ICrossChainReceiver.ReceiverBridgeAdapterConfigInput({
bridgeAdapter: CCIP_ADAPTER_TO_REMOVE,
chainIds: chainIds
});
bridgeAdapterConfig[1] = ICrossChainReceiver.ReceiverBridgeAdapterConfigInput({
bridgeAdapter: LZ_NEW_ADAPTER,
bridgeAdaptersToRemove[1] = ICrossChainReceiver.ReceiverBridgeAdapterConfigInput({
bridgeAdapter: LZ_ADAPTER_TO_REMOVE,
chainIds: chainIds
});
bridgeAdapterConfig[2] = ICrossChainReceiver.ReceiverBridgeAdapterConfigInput({
bridgeAdapter: HL_NEW_ADAPTER,
bridgeAdaptersToRemove[2] = ICrossChainReceiver.ReceiverBridgeAdapterConfigInput({
bridgeAdapter: HL_ADAPTER_TO_REMOVE,
chainIds: chainIds
});

ICrossChainReceiver(GovernanceV3Avalanche.CROSS_CHAIN_CONTROLLER).allowReceiverBridgeAdapters(
bridgeAdapterConfig
);
return bridgeAdaptersToRemove;
}

// remove old Receiver bridge adapter
ICrossChainReceiver.ReceiverBridgeAdapterConfigInput[]
memory bridgeAdaptersToRemove = new ICrossChainReceiver.ReceiverBridgeAdapterConfigInput[](3);
function _getForwarderBridgeAdaptersToRemove()
internal
pure
returns (ICrossChainForwarder.BridgeAdapterToDisable[] memory)
{
uint256[] memory chainIds = new uint256[](1);
chainIds[0] = ChainIds.MAINNET;

bridgeAdaptersToRemove[0] = ICrossChainReceiver.ReceiverBridgeAdapterConfigInput({
ICrossChainForwarder.BridgeAdapterToDisable[]
memory forwarderAdaptersToRemove = new ICrossChainForwarder.BridgeAdapterToDisable[](3);

forwarderAdaptersToRemove[0] = ICrossChainForwarder.BridgeAdapterToDisable({
bridgeAdapter: CCIP_ADAPTER_TO_REMOVE,
chainIds: chainIds
});
bridgeAdaptersToRemove[1] = ICrossChainReceiver.ReceiverBridgeAdapterConfigInput({
forwarderAdaptersToRemove[1] = ICrossChainForwarder.BridgeAdapterToDisable({
bridgeAdapter: LZ_ADAPTER_TO_REMOVE,
chainIds: chainIds
});
bridgeAdaptersToRemove[2] = ICrossChainReceiver.ReceiverBridgeAdapterConfigInput({
forwarderAdaptersToRemove[2] = ICrossChainForwarder.BridgeAdapterToDisable({
bridgeAdapter: HL_ADAPTER_TO_REMOVE,
chainIds: chainIds
});
ICrossChainReceiver(GovernanceV3Avalanche.CROSS_CHAIN_CONTROLLER)
.disallowReceiverBridgeAdapters(bridgeAdaptersToRemove);

// add new forwarding adapter paths
return forwarderAdaptersToRemove;
}

function _getReceiverBridgeAdaptersToAllow()
internal
pure
returns (ICrossChainReceiver.ReceiverBridgeAdapterConfigInput[] memory)
{
uint256[] memory chainIds = new uint256[](1);
chainIds[0] = ChainIds.MAINNET;

ICrossChainReceiver.ReceiverBridgeAdapterConfigInput[]
memory bridgeAdapterConfig = new ICrossChainReceiver.ReceiverBridgeAdapterConfigInput[](3);

bridgeAdapterConfig[0] = ICrossChainReceiver.ReceiverBridgeAdapterConfigInput({
bridgeAdapter: CCIP_NEW_ADAPTER,
chainIds: chainIds
});
bridgeAdapterConfig[1] = ICrossChainReceiver.ReceiverBridgeAdapterConfigInput({
bridgeAdapter: LZ_NEW_ADAPTER,
chainIds: chainIds
});
bridgeAdapterConfig[2] = ICrossChainReceiver.ReceiverBridgeAdapterConfigInput({
bridgeAdapter: HL_NEW_ADAPTER,
chainIds: chainIds
});

return bridgeAdapterConfig;
}

function _getForwarderBridgeAdaptersToEnable()
internal
pure
returns (ICrossChainForwarder.ForwarderBridgeAdapterConfigInput[] memory)
{
ICrossChainForwarder.ForwarderBridgeAdapterConfigInput[]
memory bridgeAdaptersToEnable = new ICrossChainForwarder.ForwarderBridgeAdapterConfigInput[](
3
Expand All @@ -87,21 +122,46 @@ contract AaveV3Avalanche_ADIAndBridgeAdaptersUpdate_20240305 is IProposalGeneric
bridgeAdaptersToEnable[0] = ICrossChainForwarder.ForwarderBridgeAdapterConfigInput({
currentChainBridgeAdapter: CCIP_NEW_ADAPTER,
destinationBridgeAdapter: DESTINATION_CCIP_NEW_ADAPTER,
destinationChainId: ChainIds.ETHEREUM
destinationChainId: ChainIds.MAINNET
});
bridgeAdaptersToEnable[1] = ICrossChainForwarder.ForwarderBridgeAdapterConfigInput({
currentChainBridgeAdapter: LZ_NEW_ADAPTER,
destinationBridgeAdapter: DESTINATION_LZ_NEW_ADAPTER,
destinationChainId: ChainIds.ETHEREUM
destinationChainId: ChainIds.MAINNET
});
bridgeAdaptersToEnable[2] = ICrossChainForwarder.ForwarderBridgeAdapterConfigInput({
currentChainBridgeAdapter: HL_NEW_ADAPTER,
destinationBridgeAdapter: DESTINATION_HL_NEW_ADAPTER,
destinationChainId: ChainIds.ETHEREUM
destinationChainId: ChainIds.MAINNET
});
return bridgeAdaptersToEnable;
}

function execute() external {
// Update CrossChainController implementation
ProxyAdmin(MiscAvalanche.PROXY_ADMIN).upgradeAndCall(
TransparentUpgradeableProxy(payable(GovernanceV3Avalanche.CROSS_CHAIN_CONTROLLER)),
NEW_CROSS_CHAIN_CONTROLLER_IMPLEMENTATION,
abi.encodeWithSignature('initializeRevision()')
);

// remove old Receiver bridge adapter
ICrossChainReceiver(GovernanceV3Avalanche.CROSS_CHAIN_CONTROLLER)
.disallowReceiverBridgeAdapters(_getReceiverBridgeAdaptersToRemove());

// remove forwarding adapters
ICrossChainForwarder(GovernanceV3Avalanche.CROSS_CHAIN_CONTROLLER).disableBridgeAdapters(
_getForwarderBridgeAdaptersToRemove()
);

// add receiver adapters
ICrossChainReceiver(GovernanceV3Avalanche.CROSS_CHAIN_CONTROLLER).allowReceiverBridgeAdapters(
_getReceiverBridgeAdaptersToAllow()
);

// add forwarding adapters
ICrossChainForwarder(GovernanceV3Avalanche.CROSS_CHAIN_CONTROLLER).enableBridgeAdapters(
bridgeAdaptersToEnable
_getForwarderBridgeAdaptersToEnable()
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -144,11 +144,11 @@ contract AaveV3Avalanche_ADIAndBridgeAdaptersUpdate_20240305_Test is ProtocolV3T
assertEq(receiverAdaptersCountAfter, receiverAdaptersAfter.length);
assertEq(receiverAdaptersAfter.length, 3);

uint256 forwarderAdaptersCount;
uint256 forwarderAdaptersCountAfter;
for (uint256 i = 0; i < forwarderBridgeAdaptersEthereumAfter.length; i++) {
if (
forwarderBridgeAdaptersEthereumAfter[i].currentChainBridgeAdapter ==
(proposal.CCIP_NEW_ADAPTER() &&
(forwarderBridgeAdaptersEthereumAfter[i].currentChainBridgeAdapter ==
proposal.CCIP_NEW_ADAPTER() &&
forwarderBridgeAdaptersEthereumAfter[i].destinationBridgeAdapter ==
proposal.DESTINATION_CCIP_NEW_ADAPTER()) ||
(forwarderBridgeAdaptersEthereumAfter[i].currentChainBridgeAdapter ==
Expand All @@ -160,10 +160,10 @@ contract AaveV3Avalanche_ADIAndBridgeAdaptersUpdate_20240305_Test is ProtocolV3T
forwarderBridgeAdaptersEthereumAfter[i].destinationBridgeAdapter ==
proposal.DESTINATION_HL_NEW_ADAPTER())
) {
forwarderAdaptersCount++;
forwarderAdaptersCountAfter++;
}
}
assertEq(forwarderAdaptersCount, forwarderBridgeAdaptersEthereumAfter.length);
assertEq(forwarderAdaptersCountAfter, forwarderBridgeAdaptersEthereumAfter.length);
assertEq(forwarderBridgeAdaptersEthereumAfter.length, 3);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,8 @@ contract AaveV3BNB_ADIAndBridgeAdaptersUpdate_20240305 is IProposalGenericExecut

function execute() external {
// Update CrossChainController implementation
ProxyAdmin(GovernanceV3BNB.PROXY_ADMIN).upgradeAndCall(
TransparentUpgradeableProxy(payable(GovernanceV3Avalanche.CROSS_CHAIN_CONTROLLER)),
ProxyAdmin(MiscBNB.PROXY_ADMIN).upgradeAndCall(
TransparentUpgradeableProxy(payable(GovernanceV3BNB.CROSS_CHAIN_CONTROLLER)),
NEW_CROSS_CHAIN_CONTROLLER_IMPLEMENTATION,
abi.encodeWithSignature('initializeRevision()')
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ contract AaveV3Base_ADIAndBridgeAdaptersUpdate_20240305_Test is ProtocolV3TestBa

// get proxy information
address cccImplementation = ProxyAdmin(MiscBase.PROXY_ADMIN).getProxyImplementation(
TransparentUpgradeableProxy(payable(GovernanceV3Arbitrum.CROSS_CHAIN_CONTROLLER))
TransparentUpgradeableProxy(payable(GovernanceV3Base.CROSS_CHAIN_CONTROLLER))
);

assertEq(cccImplementation != proposal.NEW_CROSS_CHAIN_CONTROLLER_IMPLEMENTATION(), true);
Expand Down
Loading

0 comments on commit fc4d295

Please sign in to comment.