Skip to content

Commit

Permalink
[WIP]: Register Scroll adapter on a.DI
Browse files Browse the repository at this point in the history
  • Loading branch information
sendra committed Jan 22, 2024
1 parent b44cb96 commit 0f7ba40
Show file tree
Hide file tree
Showing 5 changed files with 242 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import {IProposalGenericExecutor} from 'aave-helpers/interfaces/IProposalGenericExecutor.sol';
import {GovernanceV3Ethereum} from 'aave-address-book/GovernanceV3Ethereum.sol';
import {ChainIds} from 'aave-helpers/ChainIds.sol';

interface ICrossChainForwarder {
/**
* @notice object storing the connected pair of bridge adapters, on current and destination chain
* @param destinationBridgeAdapter address of the bridge adapter on the destination chain
* @param currentChainBridgeAdapter address of the bridge adapter deployed on current network
*/
struct ChainIdBridgeConfig {
address destinationBridgeAdapter;
address currentChainBridgeAdapter;
}
/**
* @notice object storing the pair bridgeAdapter (current deployed chain) destination chain bridge adapter configuration
* @param currentChainBridgeAdapter address of the bridge adapter deployed on current chain
* @param destinationBridgeAdapter address of the bridge adapter on the destination chain
* @param destinationChainId id of the destination chain using our own nomenclature
*/
struct ForwarderBridgeAdapterConfigInput {
address currentChainBridgeAdapter;
address destinationBridgeAdapter;
uint256 destinationChainId;
}

/**
* @notice method to get all the forwarder bridge adapters of a chain
* @param chainId id of the chain we want to get the adapters from
* @return an array of chain configurations where the bridge adapter can communicate
*/
function getForwarderBridgeAdaptersByChain(
uint256 chainId
) external view returns (ChainIdBridgeConfig[] memory);

/**
* @notice method to enable bridge adapters
* @param bridgeAdapters array of new bridge adapter configurations
*/
function enableBridgeAdapters(ForwarderBridgeAdapterConfigInput[] memory bridgeAdapters) external;
}

/**
* @title Register a.DI Scroll adapter
* @author BGD Labs @bgdlabs
* - Snapshot: Direct-to-AIP
*/
contract AaveV3Ethereum_RegisterADIScrollAdapter_20240122 is IProposalGenericExecutor {
address public constant SCROLL_ADAPTER_ETHEREUM = 0xb29F03cbCc646201eC83E9F2C164747beA84b162;
address public constant SCROLL_ADAPTER_SCROLL = 0x118DFD5418890c0332042ab05173Db4A2C1d283c;
uint256 public constant SCROLL_CHAIN_ID = ChainIds.SCROLL;

function execute() external {
ICrossChainForwarder.ForwarderBridgeAdapterConfigInput[]
memory bridgeAdaptersToEnable = new ICrossChainForwarder.ForwarderBridgeAdapterConfigInput[](
1
);

bridgeAdaptersToEnable[0] = ICrossChainForwarder.ForwarderBridgeAdapterConfigInput({
currentChainBridgeAdapter: SCROLL_ADAPTER_ETHEREUM,
destinationBridgeAdapter: SCROLL_ADAPTER_SCROLL,
destinationChainId: SCROLL_CHAIN_ID
});

ICrossChainForwarder(GovernanceV3Ethereum.CROSS_CHAIN_CONTROLLER).enableBridgeAdapters(
bridgeAdaptersToEnable
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import 'forge-std/Test.sol';
import {ProtocolV3TestBase} from 'aave-helpers/ProtocolV3TestBase.sol';
import {AaveV3Ethereum_RegisterADIScrollAdapter_20240122, ICrossChainForwarder} from './AaveV3Ethereum_RegisterADIScrollAdapter_20240122.sol';
import {GovernanceV3Scroll} from 'aave-address-book/GovernanceV3Scroll.sol';
import {GovernanceV3Ethereum} from 'aave-address-book/GovernanceV3Ethereum.sol';
import {ChainIds} from 'aave-helpers/ChainIds.sol';

interface IBaseAdapter {
/**
* @notice method to get the trusted remote address from a specified chain id
* @param chainId id of the chain from where to get the trusted remote
* @return address of the trusted remote
*/
function getTrustedRemoteByChainId(uint256 chainId) external view returns (address);
}

interface ICrossChainReceiver {
/**
* @notice method to get the current allowed receiver bridge adapters for a chain
* @param chainId id of the chain to get the allowed bridge adapter list
* @return the list of allowed bridge adapters
*/
function getReceiverBridgeAdaptersByChain(
uint256 chainId
) external view returns (address[] memory);
}

/**
* @dev Test for AaveV3Ethereum_RegisterADIScrollAdapter_20240122
* command: make test-contract filter=AaveV3Ethereum_RegisterADIScrollAdapter_20240122
*/
contract AaveV3Ethereum_RegisterADIScrollAdapter_20240122_Test is ProtocolV3TestBase {
AaveV3Ethereum_RegisterADIScrollAdapter_20240122 internal proposal;

uint256 public ethFork;
uint256 public scrollFork;

function setUp() public {
ethFork = vm.createFork(vm.rpcUrl('mainnet'), 19062921);
scrollFork = vm.createFork(vm.rpcUrl('scroll'), 2679843);

vm.selectFork(ethFork);
proposal = new AaveV3Ethereum_RegisterADIScrollAdapter_20240122();
}

/**
* @dev executes the generic test suite including e2e and config snapshots
*/
function test_defaultProposalExecution() public {
ICrossChainForwarder.ChainIdBridgeConfig[] memory ethConfig = ICrossChainForwarder(
GovernanceV3Ethereum.CROSS_CHAIN_CONTROLLER
).getForwarderBridgeAdaptersByChain(ChainIds.SCROLL);

assertEq(ethConfig.length, 1);
assertEq(ethConfig[0].destinationBridgeAdapter, proposal.SCROLL_ADAPTER_SCROLL());
assertEq(ethConfig[0].currentChainBridgeAdapter, proposal.SCROLL_ADAPTER_ETHEREUM());

vm.selectFork(scrollFork);
address[] memory scrollConfig = ICrossChainReceiver(GovernanceV3Scroll.CROSS_CHAIN_CONTROLLER)
.getReceiverBridgeAdaptersByChain(ChainIds.MAINNET);

assertEq(scrollConfig.length, 1);
assertEq(scrollConfig[0], proposal.SCROLL_ADAPTER_ETHEREUM());

assertEq(
IBaseAdapter(proposal.SCROLL_ADAPTER_SCROLL()).getTrustedRemoteByChainId(ChainIds.MAINNET),
GovernanceV3Ethereum.CROSS_CHAIN_CONTROLLER
);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
---
title: "Register a.DI Scroll adapter"
author: "BGD Labs @bgdlabs"
discussions: ""
---

## Simple Summary

Proposal to register the scroll adapter on Ethereum a.DI

## Motivation

For the Aave DAO to have control of the Aave Protocol deployed in the Scroll network, the Scroll

## Specification

## References

- Implementation: [AaveV3Ethereum](https://github.com/bgd-labs/aave-proposals-v3/blob/main/src/20240122_AaveV3Ethereum_RegisterADIScrollAdapter/AaveV3Ethereum_RegisterADIScrollAdapter_20240122.sol)
- Tests: [AaveV3Ethereum](https://github.com/bgd-labs/aave-proposals-v3/blob/main/src/20240122_AaveV3Ethereum_RegisterADIScrollAdapter/AaveV3Ethereum_RegisterADIScrollAdapter_20240122.t.sol)
- [Snapshot](TODO)
- [Discussion](TODO)

## Copyright

Copyright and related rights waived via [CC0](https://creativecommons.org/publicdomain/zero/1.0/).
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import {GovV3Helpers, IPayloadsControllerCore, PayloadsControllerUtils} from 'aave-helpers/GovV3Helpers.sol';
import {EthereumScript} from 'aave-helpers/ScriptUtils.sol';
import {AaveV3Ethereum_RegisterADIScrollAdapter_20240122} from './AaveV3Ethereum_RegisterADIScrollAdapter_20240122.sol';

/**
* @dev Deploy Ethereum
* deploy-command: make deploy-ledger contract=src/20240122_AaveV3Ethereum_RegisterADIScrollAdapter/RegisterADIScrollAdapter_20240122.s.sol:DeployEthereum chain=mainnet
* verify-command: npx catapulta-verify -b broadcast/RegisterADIScrollAdapter_20240122.s.sol/1/run-latest.json
*/
contract DeployEthereum is EthereumScript {
function run() external broadcast {
// deploy payloads
address payload0 = GovV3Helpers.deployDeterministic(
type(AaveV3Ethereum_RegisterADIScrollAdapter_20240122).creationCode
);

// compose action
IPayloadsControllerCore.ExecutionAction[]
memory actions = new IPayloadsControllerCore.ExecutionAction[](1);
actions[0] = GovV3Helpers.buildAction(payload0);

// register action at payloadsController
GovV3Helpers.createPayload(actions);
}
}

/**
* @dev Create Proposal
* command: make deploy-ledger contract=src/20240122_AaveV3Ethereum_RegisterADIScrollAdapter/RegisterADIScrollAdapter_20240122.s.sol:CreateProposal chain=mainnet
*/
contract CreateProposal is EthereumScript {
function run() external {
// create payloads
PayloadsControllerUtils.Payload[] memory payloads = new PayloadsControllerUtils.Payload[](1);

// compose actions for validation
IPayloadsControllerCore.ExecutionAction[]
memory actionsEthereum = new IPayloadsControllerCore.ExecutionAction[](1);
actionsEthereum[0] = GovV3Helpers.buildAction(
type(AaveV3Ethereum_RegisterADIScrollAdapter_20240122).creationCode
);
payloads[0] = GovV3Helpers.buildMainnetPayload(vm, actionsEthereum);

// create proposal
vm.startBroadcast();
GovV3Helpers.createProposal(
vm,
payloads,
GovV3Helpers.ipfsHashFile(
vm,
'src/20240122_AaveV3Ethereum_RegisterADIScrollAdapter/RegisterADIScrollAdapter.md'
)
);
}
}
13 changes: 13 additions & 0 deletions src/20240122_AaveV3Ethereum_RegisterADIScrollAdapter/config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import {ConfigFile} from '../../generator/types';
export const config: ConfigFile = {
rootOptions: {
author: 'BGD Labs @bgdlabs',
pools: ['AaveV3Ethereum'],
title: 'Register a.DI Scroll adapter',
shortName: 'RegisterADIScrollAdapter',
date: '20240122',
discussion: '',
snapshot: '',
},
poolOptions: {AaveV3Ethereum: {configs: {OTHERS: {}}, cache: {blockNumber: 19062723}}},
};

0 comments on commit 0f7ba40

Please sign in to comment.