Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Add base ccc update payload. #305

Merged
merged 10 commits into from
Jul 10, 2024
Merged
15 changes: 15 additions & 0 deletions src/adi/BaseADIPayloadUpdate.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
// SPDX-License-Identifier: AGPL-3.0
pragma solidity ^0.8.0;

import {IProposalGenericExecutor} from '../interfaces/IProposalGenericExecutor.sol';

abstract contract BaseADIPayloadUpdate is IProposalGenericExecutor {
address public immutable CROSS_CHAIN_CONTROLLER;

/**
* @param crossChainController address of the CCC of the network where payload will be deployed
*/
constructor(address crossChainController) {
CROSS_CHAIN_CONTROLLER = crossChainController;
}
}
12 changes: 4 additions & 8 deletions src/adi/BaseAdaptersUpdate.sol
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import {IProposalGenericExecutor} from '../interfaces/IProposalGenericExecutor.sol';
import './BaseReceiverAdaptersUpdate.sol';
import './BaseForwarderAdaptersUpdate.sol';
import './BaseADIPayloadUpdate.sol';

/**
* @title Base payload aDI and bridge adapters update
Expand All @@ -12,18 +12,14 @@ import './BaseForwarderAdaptersUpdate.sol';
abstract contract BaseAdaptersUpdate is
BaseReceiverAdaptersUpdate,
BaseForwarderAdaptersUpdate,
IProposalGenericExecutor
BaseADIPayloadUpdate
{
address public immutable CROSS_CHAIN_CONTROLLER;

/**
* @param crossChainController address of the CCC of the network where payload will be deployed
*/
constructor(address crossChainController) {
CROSS_CHAIN_CONTROLLER = crossChainController;
}
constructor(address crossChainController) BaseADIPayloadUpdate(crossChainController) {}

function execute() public override {
function execute() public virtual {
executeReceiversUpdate(CROSS_CHAIN_CONTROLLER);

executeForwardersUpdate(CROSS_CHAIN_CONTROLLER);
Expand Down
48 changes: 48 additions & 0 deletions src/adi/BaseCCCUpdate.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
// SPDX-License-Identifier: AGPL-3.0
pragma solidity ^0.8.0;

import {TransparentUpgradeableProxy} from 'solidity-utils/contracts/transparent-proxy/TransparentUpgradeableProxy.sol';
import {TransparentProxyFactory} from 'solidity-utils/contracts/transparent-proxy/TransparentProxyFactory.sol';
import {ProxyAdmin} from 'solidity-utils/contracts/transparent-proxy/ProxyAdmin.sol';
import './BaseADIPayloadUpdate.sol';

/**
* @param crossChainController address of the CCC of the network where payload will be deployed
* @param newCCCImpl address of the new ccc implementation
* @param proxyAdmin address of the proxy admin owner of ccc
*/
struct CCCUpdateArgs {
address crossChainController;
address crossChainControllerImpl;
address proxyAdmin;
}

/**
* @title Base payload to update CCC
* @author BGD Labs @bgdlabs
*/
abstract contract BaseCCCUpdate is BaseADIPayloadUpdate {
address public immutable NEW_CCC_IMPL;
address public immutable PROXY_ADMIN;

/*
* @param cccUpdateArgs arguments necessary to update ccc implementation
*/
constructor(
CCCUpdateArgs memory cccUpdateArgs
) BaseADIPayloadUpdate(cccUpdateArgs.crossChainController) {
NEW_CCC_IMPL = cccUpdateArgs.crossChainControllerImpl;
PROXY_ADMIN = cccUpdateArgs.proxyAdmin;
}

function getInitializeSignature() public virtual returns (bytes memory);

/// @inheritdoc IProposalGenericExecutor
function execute() external virtual override {
ProxyAdmin(PROXY_ADMIN).upgradeAndCall(
TransparentUpgradeableProxy(payable(CROSS_CHAIN_CONTROLLER)),
NEW_CCC_IMPL,
getInitializeSignature()
);
}
}
29 changes: 22 additions & 7 deletions src/adi/test/ADITestBase.sol
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {ICrossChainReceiver, ICrossChainForwarder} from 'aave-address-book/commo
import {ChainIds, ChainHelpers} from '../../ChainIds.sol';
import {GovV3Helpers} from '../../GovV3Helpers.sol';
import {IBaseAdaptersUpdate} from '../interfaces/IBaseAdaptersUpdate.sol';
import {ProxyHelpers} from '../../ProxyHelpers.sol';

import {GovernanceV3Ethereum} from 'aave-address-book/GovernanceV3Ethereum.sol';
import {GovernanceV3Polygon} from 'aave-address-book/GovernanceV3Polygon.sol';
Expand Down Expand Up @@ -40,6 +41,7 @@ contract ADITestBase is Test {
}

struct CCCConfig {
address crossChainControllerImpl;
ReceiverConfigByChain[] receiverConfigs;
ReceiverAdaptersByChain[] receiverAdaptersConfig;
ForwarderAdaptersByChain[] forwarderAdaptersConfig;
Expand Down Expand Up @@ -89,7 +91,8 @@ contract ADITestBase is Test {
string memory reportName,
address crossChainController,
address payload,
bool runE2E
bool runE2E,
Vm vm
) public returns (CCCConfig memory, CCCConfig memory) {
string memory beforeString = string(abi.encodePacked('adi_', reportName, '_before'));
CCCConfig memory configBefore = createConfigurationSnapshot(beforeString, crossChainController);
Expand Down Expand Up @@ -128,7 +131,7 @@ contract ADITestBase is Test {
memory forwardersToEnable = IBaseAdaptersUpdate(payload).getForwarderBridgeAdaptersToEnable();
if (forwardersToEnable.length != 0) {
_testCorrectForwarderAdaptersConfiguration(payload, crossChainController, forwardersToEnable);
_testDestinationAdapterIsRegistered(payload, crossChainController, forwardersToEnable);
_testDestinationAdapterIsRegistered(forwardersToEnable);
}
ICrossChainForwarder.BridgeAdapterToDisable[] memory forwardersToRemove = IBaseAdaptersUpdate(
payload
Expand All @@ -148,8 +151,6 @@ contract ADITestBase is Test {
}

function _testDestinationAdapterIsRegistered(
address payload,
address crossChainController,
ICrossChainForwarder.ForwarderBridgeAdapterConfigInput[] memory forwardersToEnable
) internal {
DestinationPayload[] memory destinationPayloads = getDestinationPayloadsByChain();
Expand Down Expand Up @@ -382,31 +383,42 @@ contract ADITestBase is Test {
string memory reportName,
address crossChainController
) public returns (CCCConfig memory) {
return createConfigurationSnapshot(reportName, crossChainController, true, true, true);
return createConfigurationSnapshot(reportName, crossChainController, true, true, true, true);
}

function createConfigurationSnapshot(
string memory reportName,
address crossChainController,
bool receiverConfigs,
bool receiverAdapterConfigs,
bool forwarderAdapterConfigs
bool forwarderAdapterConfigs,
bool cccImplUpdate
kyzia551 marked this conversation as resolved.
Show resolved Hide resolved
) public returns (CCCConfig memory) {
string memory path = string(abi.encodePacked('./reports/', reportName, '.json'));
// overwrite with empty json to later be extended
vm.writeFile(
path,
'{ "receiverConfigsByChain": {}, "receiverAdaptersByChain": {}, "forwarderAdaptersByChain": {}}'
'{ "cccImplementation": {}, "receiverConfigsByChain": {}, "receiverAdaptersByChain": {}, "forwarderAdaptersByChain": {}}'
);
vm.serializeUint('root', 'chainId', block.chainid);
CCCConfig memory config = _getCCCConfig(crossChainController);
if (receiverConfigs) _writeReceiverConfigs(path, config);
if (receiverAdapterConfigs) _writeReceiverAdapters(path, config);
if (forwarderAdapterConfigs) _writeForwarderAdatpers(path, config);
if (cccImplUpdate) _writeCCCImplUpdate(path, config);

return config;
}

function _writeCCCImplUpdate(string memory path, CCCConfig memory config) internal {
string memory output = vm.serializeAddress(
'root',
'crossChainControllerImpl',
config.crossChainControllerImpl
);
vm.writeJson(output, path);
}

function _writeForwarderAdatpers(string memory path, CCCConfig memory config) internal {
// keys for json stringification
string memory forwarderAdaptersKey = 'forwarderAdapters';
Expand Down Expand Up @@ -507,6 +519,9 @@ contract ADITestBase is Test {
function _getCCCConfig(address ccc) internal view returns (CCCConfig memory) {
CCCConfig memory config;

// get crossChainController implementation
config.crossChainControllerImpl = ProxyHelpers
.getInitializableAdminUpgradeabilityProxyImplementation(vm, ccc);
// get supported networks
uint256[] memory receiverSupportedChains = ICrossChainReceiver(ccc).getSupportedChains();
ReceiverConfigByChain[] memory receiverConfigs = new ReceiverConfigByChain[](
Expand Down
3 changes: 2 additions & 1 deletion tests/adi/SimpleOneToManyAdapterUpdatePayloadTest.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,8 @@ contract SimpleOneToManyAdapterUpdatePayloadTest is ADITestBase {
'test_adi_diffs',
GovernanceV3Polygon.CROSS_CHAIN_CONTROLLER,
address(payload),
true
true,
vm
);
}
}