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 gov v3 helpers #139

Merged
merged 39 commits into from
Oct 12, 2023
Merged
Show file tree
Hide file tree
Changes from 24 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
aa91b5b
feat: add gov v3 helpers
sendra Aug 18, 2023
727799c
fix: added helper methods
sendra Aug 18, 2023
180c843
fix: patch stdStorage
sakulstra Aug 22, 2023
ef7e94f
fix: make it build
sakulstra Aug 22, 2023
1993fb3
fix: v2 helper fix
sakulstra Aug 22, 2023
240487d
fix: deduplicate ipfs tools
sakulstra Aug 31, 2023
c7497fa
fix: stash local changes
sakulstra Aug 31, 2023
2e01b7b
feat: push gov v3helpers
sakulstra Sep 4, 2023
f103cde
fix: update aligned with discussion
sakulstra Sep 4, 2023
5ff3165
feat: add proposal execution flow
sakulstra Sep 5, 2023
9d42de2
fix: allow overwriting proposals count
sakulstra Sep 5, 2023
f471fa2
feat: inject payloads
sakulstra Sep 6, 2023
ca11b26
fix: update to new address book
sakulstra Sep 6, 2023
40f2ec0
fix: change visibility
sakulstra Sep 6, 2023
2d12060
feat: initial ready proposal
sakulstra Sep 6, 2023
0a4b492
feat: implement readyProposal for govv3
sakulstra Sep 6, 2023
ff9872f
feat: add overload for single proposal
sakulstra Sep 6, 2023
d2ea61f
fix: update scripts
sakulstra Sep 13, 2023
1bf6a84
fix: update ipfs test
sakulstra Sep 18, 2023
7054d28
fix: add broken methods
sakulstra Sep 18, 2023
b3e9c86
feat: integrate cli into helpers
sakulstra Sep 19, 2023
b871752
stash: stash local changes
sakulstra Sep 19, 2023
8d5da78
feat: add overloads
sakulstra Sep 20, 2023
0ed5cf6
docs: add a sentence on readme
sakulstra Sep 20, 2023
fd5583f
Update src/GovV3Helpers.sol
sakulstra Sep 20, 2023
6297100
fix: resolve conflicts
sakulstra Sep 26, 2023
98b82c0
fix: add voting script
sakulstra Sep 27, 2023
2b1fbba
fix: add readme
sakulstra Sep 27, 2023
cc1d0b4
fix: some patches to storage utils
sakulstra Oct 9, 2023
9bb500a
fix: add activateVoting to test
sakulstra Oct 9, 2023
3ed23bb
fix: remove unncessary tests
sakulstra Oct 9, 2023
4be38d7
fix: last few patches
sakulstra Oct 9, 2023
008881e
Update src/ChainIds.sol
sakulstra Oct 9, 2023
f30425c
fix: add sepolia rpc
sakulstra Oct 9, 2023
9d96558
fix: typo
sakulstra Oct 9, 2023
892f5a0
Update src/GovV3Helpers.sol
sakulstra Oct 9, 2023
4ef2de7
Update src/GovV3Helpers.sol
sakulstra Oct 9, 2023
42c3ded
fix: resolve conflicts
sakulstra Oct 12, 2023
f9a1dd5
fix: update address book
sakulstra Oct 12, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,14 @@

This package contains various contracts which allow you to streamline testing within the aave protocol in foundry.

## GovHelpers
## GovHelpers (deprecated)

These helpers allow you to create and execute proposals on L1 so you don't have to care about having enough proposition power, timings, etc.

## GovV3Helpers

These helpers allow the creation of proposal for aave governance v3.

## ProxyHelpers

These helpers allow you to fetch the current implementation & admin for a specified proxy.
Expand All @@ -19,3 +23,7 @@ These helpers allow you to simulate execution of proposals on governance control
The ProtocolV3TestBase is intended to be used with proposals that alter a V3 pool. While the `helpers` are libraries, you can use from where ever you want `ProtocolV3TestBase` is intended to be inherited from in your test via `is ProtocolV3TestBase`.

When inheriting from `ProtocolV3TestBase` you have access to methods to create readable configuration snapshots of a pool and e2e tests of a pool.

## ProtocolV2TestBase

Analog to ProtocolV3TestBase but for v2 pools.
4 changes: 3 additions & 1 deletion foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ fantom = "${RPC_FANTOM}"
harmony = "${RPC_HARMONY}"
metis = "${RPC_METIS}"
base = "${RPC_BASE}"
sepolia = "${RPC_SEPOLIA}"

[etherscan]
mainnet={key="${ETHERSCAN_API_KEY_MAINNET}",chainId=1}
Expand All @@ -27,6 +28,7 @@ avalanche={key="${ETHERSCAN_API_KEY_AVALANCHE}",chainId=43114}
polygon={key="${ETHERSCAN_API_KEY_POLYGON}",chainId=137}
arbitrum={key="${ETHERSCAN_API_KEY_ARBITRUM}",chainId=42161}
fantom={key="${ETHERSCAN_API_KEY_FANTOM}",chainId=250}
base = { key="any", chainId=8453, url='https://basescan.org/' }
base={key="any",chainId=8453,url='https://basescan.org/'}
sepolia={key="${ETHERSCAN_API_KEY_MAINNET}",chainId=11155111}

# See more config options https://github.com/gakonst/foundry/tree/master/config
2 changes: 1 addition & 1 deletion lib/aave-address-book
Submodule aave-address-book updated 199 files
40 changes: 40 additions & 0 deletions src/ChainIds.sol
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
import {Vm} from 'forge-std/Vm.sol';

library ChainIds {
uint256 internal constant MAINNET = 1;
Expand All @@ -16,3 +17,42 @@ library ChainIds {
uint256 internal constant SEPOLIA = 11155111;
uint256 internal constant HARMONY = 1666600000;
}

library ChainHelpers {
error UnknownChainId();

function selectChain(Vm vm, uint256 chainId) internal returns (uint256, uint256) {
uint256 previousFork = vm.activeFork();
uint256 newFork;
if (chainId == ChainIds.MAINNET) {
newFork = vm.createFork(vm.rpcUrl('mainnet'));
} else if (chainId == ChainIds.OPTIMISM) {
newFork = vm.createFork(vm.rpcUrl('optimism'));
} else if (chainId == ChainIds.BSC) {
newFork = vm.createFork(vm.rpcUrl('bsc'));
} else if (chainId == ChainIds.POLYGON) {
newFork = vm.createFork(vm.rpcUrl('polygon'));
} else if (chainId == ChainIds.FANTOM) {
newFork = vm.createFork(vm.rpcUrl('fantom'));
} else if (chainId == ChainIds.ZK_SYNC) {
newFork = vm.createFork(vm.rpcUrl('tkSync'));
sakulstra marked this conversation as resolved.
Show resolved Hide resolved
} else if (chainId == ChainIds.METIS) {
newFork = vm.createFork(vm.rpcUrl('metis'));
} else if (chainId == ChainIds.ZK_EVM) {
newFork = vm.createFork(vm.rpcUrl('zkEvm'));
} else if (chainId == ChainIds.BASE) {
newFork = vm.createFork(vm.rpcUrl('base'));
} else if (chainId == ChainIds.ARBITRUM) {
newFork = vm.createFork(vm.rpcUrl('arbitrum'));
} else if (chainId == ChainIds.AVALANCHE) {
newFork = vm.createFork(vm.rpcUrl('avalanche'));
} else if (chainId == ChainIds.SEPOLIA) {
newFork = vm.createFork(vm.rpcUrl('sepolia'));
} else if (chainId == ChainIds.HARMONY) {
newFork = vm.createFork(vm.rpcUrl('harmony'));
} else {
revert UnknownChainId();
}
return (previousFork, newFork);
}
}
32 changes: 2 additions & 30 deletions src/GovHelpers.sol
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ pragma abicoder v2;

import {Vm} from 'forge-std/Vm.sol';
import {console2} from 'forge-std/console2.sol';
import {IpfsUtils} from './IpfsUtils.sol';
import {AaveGovernanceV2, IAaveGovernanceV2, IExecutorWithTimelock} from 'aave-address-book/AaveGovernanceV2.sol';
import {IPoolAddressesProvider} from 'aave-address-book/AaveV3.sol';
import {AaveV3Avalanche} from 'aave-address-book/AaveV3Avalanche.sol';
Expand Down Expand Up @@ -42,37 +43,8 @@ library GovHelpers {
bool withDelegatecall;
}

function ipfsHashFile(Vm vm, string memory filePath, bool upload) internal returns (bytes32) {
string[] memory inputs = new string[](8);
inputs[0] = 'npx';
inputs[1] = '--yes';
inputs[2] = '-s';
inputs[3] = '@bgd-labs/aave-cli';
inputs[4] = 'ipfs';
inputs[5] = filePath;
inputs[6] = '-u';
inputs[7] = vm.toString(upload);
bytes memory bs58Hash = vm.ffi(inputs);
// currenty there is no better way as ffi silently fails
// revisit once https://github.com/foundry-rs/foundry/pull/4908 progresses
require(
bs58Hash.length != 0,
'CALCULATED_HASH_IS_ZERO_CHECK_IF_YARN_DEPENDENCIES_ARE_INSTALLED'
);
console2.logString('Info: This preview will only work when the file has been uploaded to ipfs');
console2.logString(
string(
abi.encodePacked(
'Preview: https://app.aave.com/governance/ipfs-preview/?ipfsHash=',
vm.toString(bs58Hash)
)
)
);
return bytes32(bs58Hash);
}

function ipfsHashFile(Vm vm, string memory filePath) internal returns (bytes32) {
return ipfsHashFile(vm, filePath, false);
return IpfsUtils.ipfsHashFile(vm, filePath, false);
}

function buildMainnet(address payloadAddress) internal pure returns (Payload memory) {
Expand Down
Loading