Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion .gitmodules
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[submodule "lib/aave-helpers"]
path = lib/aave-helpers
url = https://github.com/bgd-labs/aave-helpers
branch = main
branch = feat/multi-deploy
2 changes: 2 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ deploy-ledger-zk :; FOUNDRY_PROFILE=zksync forge script $(if $(filter zksync,${c
deploy-ledger :; forge script $(if $(filter zksync,${chain}),--zksync) ${contract} --rpc-url ${chain} $(if ${dry},--sender 0x73AF3bcf944a6559933396c1577B257e2054D935 -vvvv, --ledger --mnemonic-indexes ${MNEMONIC_INDEX} --sender ${LEDGER_SENDER} --verify -vvvv --slow --broadcast) $(if ${legacy}, --legacy, )
deploy-pk :; forge script $(if $(filter zksync,${chain}),--zksync) ${contract} --rpc-url ${chain} $(if ${dry},--sender 0x73AF3bcf944a6559933396c1577B257e2054D935 -vvvv, --private-key ${PRIVATE_KEY} --verify -vvvv --slow --broadcast)

deploy-multichain-ledger :; forge script ${contract} $(if ${dry},--sender 0x73AF3bcf944a6559933396c1577B257e2054D935 -vvvv, --ledger --mnemonic-indexes ${MNEMONIC_INDEX} --sender ${LEDGER_SENDER} --verify -vvvv --slow --broadcast) $(if ${legacy}, --legacy, )

# Utilities
download :; cast etherscan-source --chain ${chain} -d src/etherscan/${chain}_${address} ${address}
git-diff :
Expand Down
4 changes: 2 additions & 2 deletions foundry.lock
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"lib/aave-helpers": {
"branch": {
"name": "main",
"rev": "7eec1e60b71e0904d7f1afa5743965b9524bf30a"
"name": "feat/multi-deploy",
"rev": "89d808f97df37a9f38ceb9a70ec46271ee005054"
}
}
}
10 changes: 0 additions & 10 deletions foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -42,16 +42,6 @@ out = 'out/cancun'
evm_version = 'cancun'
cache_path = 'cache/cancun'

[profile.deploy]
out = 'out/shanghai'
evm_version = 'shanghai'
cache_path = 'cache/shanghai'

[profile.linea]
out = 'out/london'
evm_version = 'london'
cache_path = 'cache/london'

[rpc_endpoints]
mainnet = "${RPC_MAINNET}"
optimism = "${RPC_OPTIMISM}"
Expand Down
54 changes: 20 additions & 34 deletions generator/features/__snapshots__/assetListing.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -218,31 +218,24 @@ contract AaveV3Ethereum_Test_20231023_Test is ProtocolV3TestBase {
"defaultScript": "// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import {Script} from 'forge-std/Script.sol';
import {ChainIds} from 'solidity-utils/contracts/utils/ChainHelpers.sol';
import {GovV3Helpers, IPayloadsControllerCore, PayloadsControllerUtils} from 'aave-helpers/src/GovV3Helpers.sol';
import {GovernanceV3Ethereum} from 'aave-address-book/GovernanceV3Ethereum.sol';

import {EthereumScript} from 'solidity-utils/contracts/utils/ScriptUtils.sol';
import {AaveV3Ethereum_Test_20231023} from './AaveV3Ethereum_Test_20231023.sol';

/**
* @dev Deploy Ethereum
* deploy-command: make deploy-ledger contract=src/20231023_AaveV3Ethereum_Test/Test_20231023.s.sol:DeployEthereum chain=mainnet
* verify-command: FOUNDRY_PROFILE=deploy npx catapulta-verify -b broadcast/Test_20231023.s.sol/1/run-latest.json
* @dev Deploy and Register Payloads on all networks
* deploy-command: make deploy-multichain-ledger contract=src/20231023_AaveV3Ethereum_Test/Test_20231023.s.sol:DeployPayloads
*/
contract DeployEthereum is EthereumScript {
function run() external broadcast {
// deploy payloads
address payload0 = GovV3Helpers.deployDeterministic(
type(AaveV3Ethereum_Test_20231023).creationCode
);

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

// register action at payloadsController
GovV3Helpers.createPayload(actions);
contract DeployPayloads is Script {
function run() external {
// Ethereum
bytes[] memory ethereumPayload = new bytes[](1);
ethereumPayload[0] = type(AaveV3Ethereum_Test_20231023).creationCode;
GovV3Helpers.deployRegisterPayload(vm, ChainIds.ETHEREUM, ethereumPayload);
}
}

Expand Down Expand Up @@ -498,31 +491,24 @@ contract AaveV3Ethereum_Test_20231023_Test is ProtocolV3TestBase {
"defaultScript": "// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import {Script} from 'forge-std/Script.sol';
import {ChainIds} from 'solidity-utils/contracts/utils/ChainHelpers.sol';
import {GovV3Helpers, IPayloadsControllerCore, PayloadsControllerUtils} from 'aave-helpers/src/GovV3Helpers.sol';
import {GovernanceV3Ethereum} from 'aave-address-book/GovernanceV3Ethereum.sol';

import {EthereumScript} from 'solidity-utils/contracts/utils/ScriptUtils.sol';
import {AaveV3Ethereum_Test_20231023} from './AaveV3Ethereum_Test_20231023.sol';

/**
* @dev Deploy Ethereum
* deploy-command: make deploy-ledger contract=src/20231023_AaveV3Ethereum_Test/Test_20231023.s.sol:DeployEthereum chain=mainnet
* verify-command: FOUNDRY_PROFILE=deploy npx catapulta-verify -b broadcast/Test_20231023.s.sol/1/run-latest.json
* @dev Deploy and Register Payloads on all networks
* deploy-command: make deploy-multichain-ledger contract=src/20231023_AaveV3Ethereum_Test/Test_20231023.s.sol:DeployPayloads
*/
contract DeployEthereum is EthereumScript {
function run() external broadcast {
// deploy payloads
address payload0 = GovV3Helpers.deployDeterministic(
type(AaveV3Ethereum_Test_20231023).creationCode
);

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

// register action at payloadsController
GovV3Helpers.createPayload(actions);
contract DeployPayloads is Script {
function run() external {
// Ethereum
bytes[] memory ethereumPayload = new bytes[](1);
ethereumPayload[0] = type(AaveV3Ethereum_Test_20231023).creationCode;
GovV3Helpers.deployRegisterPayload(vm, ChainIds.ETHEREUM, ethereumPayload);
}
}

Expand Down
27 changes: 10 additions & 17 deletions generator/features/__snapshots__/priceFeedsUpdate.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -120,31 +120,24 @@ contract AaveV3Ethereum_Test_20231023_Test is ProtocolV3TestBase {
"defaultScript": "// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import {Script} from 'forge-std/Script.sol';
import {ChainIds} from 'solidity-utils/contracts/utils/ChainHelpers.sol';
import {GovV3Helpers, IPayloadsControllerCore, PayloadsControllerUtils} from 'aave-helpers/src/GovV3Helpers.sol';
import {GovernanceV3Ethereum} from 'aave-address-book/GovernanceV3Ethereum.sol';

import {EthereumScript} from 'solidity-utils/contracts/utils/ScriptUtils.sol';
import {AaveV3Ethereum_Test_20231023} from './AaveV3Ethereum_Test_20231023.sol';

/**
* @dev Deploy Ethereum
* deploy-command: make deploy-ledger contract=src/20231023_AaveV3Ethereum_Test/Test_20231023.s.sol:DeployEthereum chain=mainnet
* verify-command: FOUNDRY_PROFILE=deploy npx catapulta-verify -b broadcast/Test_20231023.s.sol/1/run-latest.json
* @dev Deploy and Register Payloads on all networks
* deploy-command: make deploy-multichain-ledger contract=src/20231023_AaveV3Ethereum_Test/Test_20231023.s.sol:DeployPayloads
*/
contract DeployEthereum is EthereumScript {
function run() external broadcast {
// deploy payloads
address payload0 = GovV3Helpers.deployDeterministic(
type(AaveV3Ethereum_Test_20231023).creationCode
);

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

// register action at payloadsController
GovV3Helpers.createPayload(actions);
contract DeployPayloads is Script {
function run() external {
// Ethereum
bytes[] memory ethereumPayload = new bytes[](1);
ethereumPayload[0] = type(AaveV3Ethereum_Test_20231023).creationCode;
GovV3Helpers.deployRegisterPayload(vm, ChainIds.ETHEREUM, ethereumPayload);
}
}

Expand Down
27 changes: 10 additions & 17 deletions generator/features/__snapshots__/rateUpdates.spec.ts.snap
Original file line number Diff line number Diff line change
Expand Up @@ -226,31 +226,24 @@ contract AaveV2EthereumAMM_Test_20231023_Test is ProtocolV2TestBase {
"defaultScript": "// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import {Script} from 'forge-std/Script.sol';
import {ChainIds} from 'solidity-utils/contracts/utils/ChainHelpers.sol';
import {GovV3Helpers, IPayloadsControllerCore, PayloadsControllerUtils} from 'aave-helpers/src/GovV3Helpers.sol';
import {GovernanceV3Ethereum} from 'aave-address-book/GovernanceV3Ethereum.sol';

import {EthereumScript} from 'solidity-utils/contracts/utils/ScriptUtils.sol';
import {AaveV2EthereumAMM_Test_20231023} from './AaveV2EthereumAMM_Test_20231023.sol';

/**
* @dev Deploy Ethereum
* deploy-command: make deploy-ledger contract=src/20231023_AaveV2EthereumAMM_Test/Test_20231023.s.sol:DeployEthereum chain=mainnet
* verify-command: FOUNDRY_PROFILE=deploy npx catapulta-verify -b broadcast/Test_20231023.s.sol/1/run-latest.json
* @dev Deploy and Register Payloads on all networks
* deploy-command: make deploy-multichain-ledger contract=src/20231023_AaveV2EthereumAMM_Test/Test_20231023.s.sol:DeployPayloads
*/
contract DeployEthereum is EthereumScript {
function run() external broadcast {
// deploy payloads
address payload0 = GovV3Helpers.deployDeterministic(
type(AaveV2EthereumAMM_Test_20231023).creationCode
);

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

// register action at payloadsController
GovV3Helpers.createPayload(actions);
contract DeployPayloads is Script {
function run() external {
// Ethereum
bytes[] memory ethereumPayload = new bytes[](1);
ethereumPayload[0] = type(AaveV2EthereumAMM_Test_20231023).creationCode;
GovV3Helpers.deployRegisterPayload(vm, ChainIds.ETHEREUM, ethereumPayload);
}
}

Expand Down
82 changes: 60 additions & 22 deletions generator/templates/script.template.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import {
CHAIN_TO_CHAIN_ID,
generateContractName,
generateFolderName,
getChainAlias,
Expand All @@ -20,7 +19,10 @@ export function generateScript(options: Options) {
const hasWhitelabelPool = options.pools.some((pool) => isWhitelabelPool(pool));

// generate imports
template += `import {${['Ethereum', ...chains.filter((c) => c !== 'Ethereum' && c !== 'ZkSync')]
template += `import {${[
'Ethereum',
...chains.filter((c) => hasWhitelabelPool && c !== 'Ethereum' && c !== 'ZkSync'),
]
.map((chain) => `${chain}Script`)
.join(', ')}} from 'solidity-utils/contracts/utils/ScriptUtils.sol';\n`;
template += options.pools
Expand All @@ -39,54 +41,90 @@ export function generateScript(options: Options) {
acc[chain].push({contractName, pool});
return acc;
}, {});
const filteredPoolToChainsMap = Object.keys(poolsToChainsMap).filter((c) => c !== 'ZkSync');

// generate chain scripts
template += Object.keys(poolsToChainsMap)
.filter((c) => c !== 'ZkSync')
.map((chain) => {
return `/**
if (hasWhitelabelPool) {
template += filteredPoolToChainsMap
.map((chain) => {
return `/**
* @dev Deploy ${chain}
* deploy-command: make deploy-ledger contract=src/${folderName}/${fileName}.s.sol:Deploy${chain} chain=${getChainAlias(
chain,
)}
* verify-command: FOUNDRY_PROFILE=deploy npx catapulta-verify -b broadcast/${fileName}.s.sol/${
CHAIN_TO_CHAIN_ID[chain]
}/run-latest.json
*/
contract Deploy${chain} is ${chain}Script {
function run() external broadcast {
// deploy payloads
${poolsToChainsMap[chain]
.map(
({contractName, pool}, ix) =>
`address payload${ix} = GovV3Helpers.deployDeterministic(type(${contractName}).creationCode);`,
`GovV3Helpers.deployDeterministic(type(${contractName}).creationCode);`,
)
.join('\n')}
}
}`;
})
.join('\n\n');
template += '\n\n';

// generate permissioned-payload calldata script
template += filteredPoolToChainsMap
.map((chain) => {
return `/**
* @dev Generate Calldata for ${chain}
* deploy-command: forge script --rpc-url ${getChainAlias(chain)} src/${folderName}/${fileName}.s.sol:RegisterPayloadCalldata${chain}
*/
contract RegisterPayloadCalldata${chain} is ${chain}Script {
function run() external view {
// compose action
IPayloadsControllerCore.ExecutionAction[] memory actions = new IPayloadsControllerCore.ExecutionAction[](${
poolsToChainsMap[chain].length
});
${poolsToChainsMap[chain]
.map(
({contractName, pool}, ix) => `actions[${ix}] = GovV3Helpers.buildAction(payload${ix});`,
({contractName, pool}, ix) =>
`actions[${ix}] = GovV3Helpers.buildAction(type(${contractName}).creationCode);`,
)
.join('\n')}

// register action at payloadsController
${
hasWhitelabelPool
? `GovV3Helpers.createPermissionedPayloadCalldata(GovernanceV3${poolsToChainsMap[chain][0].pool.replace('AaveV3', '')}.PERMISSIONED_PAYLOADS_CONTROLLER, actions);`
: 'GovV3Helpers.createPayload(actions);'
}
GovV3Helpers.createPermissionedPayloadCalldata(GovernanceV3${poolsToChainsMap[chain][0].pool.replace('AaveV3', '')}.PERMISSIONED_PAYLOADS_CONTROLLER, actions);
}
}`;
})
.join('\n\n');
template += '\n\n';
})
.join('\n\n');
template += '\n\n';
} else {
// multi chain deploy scripts
if (filteredPoolToChainsMap.length > 0) {
template += `
/**
* @dev Deploy and Register Payloads on all networks
* deploy-command: make deploy-multichain-ledger contract=src/${folderName}/${fileName}.s.sol:DeployPayloads
*/
contract DeployPayloads is Script {
function run() external {
${filteredPoolToChainsMap
.map(
(chain) => `
// ${chain}
bytes[] memory ${chain.toLowerCase()}Payload = new bytes[](${poolsToChainsMap[chain].length});
${poolsToChainsMap[chain]
.map(
({contractName, pool}, ix) =>
`${chain.toLowerCase()}Payload[${ix}] = type(${contractName}).creationCode;`,
)
.join('\n')}
GovV3Helpers.deployRegisterPayload(vm, ChainIds.${chain.toUpperCase()}, ${chain.toLowerCase()}Payload);
`,
)
.join('\n')}
}
}`;
}
template += '\n\n';

// generate proposal creation script
if (!hasWhitelabelPool) {
// generate proposal creation script
template += `/**
* @dev Create Proposal
* command: make deploy-ledger contract=src/${folderName}/${fileName}.s.sol:CreateProposal chain=mainnet
Expand Down
6 changes: 6 additions & 0 deletions generator/utils/importsResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@ function findMatch(code: string, needle: string) {
*/
export function prefixWithImports(code: string) {
let imports = '';
if (findMatch(code, 'Script')) {
imports += `import {Script} from 'forge-std/Script.sol';\n`;
}
if (findMatch(code, 'ChainIds')) {
imports += `import {ChainIds} from 'solidity-utils/contracts/utils/ChainHelpers.sol';\n`;
}
const govMatches = findMatches(code, GovernanceImports);
// gov related imports
if (govMatches.length > 0)
Expand Down
2 changes: 1 addition & 1 deletion lib/aave-helpers
Loading