Skip to content

Commit

Permalink
feat: add zksync (#24)
Browse files Browse the repository at this point in the history
* feat: add zksync

* chore: fix comment
  • Loading branch information
brotherlymite authored Dec 10, 2024
1 parent 0731cd5 commit 947d6be
Show file tree
Hide file tree
Showing 9 changed files with 64 additions and 14 deletions.
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,5 @@ git-diff :
deploy-ledger :; FOUNDRY_PROFILE=${chain} forge script $(if $(filter zksync,${chain}),--zksync) ${contract} --rpc-url ${chain} $(if ${dry},--sender 0x25F2226B597E8F9514B3F68F00f494cF4f286491 -vvvv, --ledger --mnemonic-indexes ${MNEMONIC_INDEX} --sender ${LEDGER_SENDER} --verify -vvvv --slow --broadcast)
deploy-pk :; FOUNDRY_PROFILE=${chain} forge script $(if $(filter zksync,${chain}),--zksync) ${contract} --rpc-url ${chain} $(if ${dry},--sender 0x25F2226B597E8F9514B3F68F00f494cF4f286491 -vvvv, --private-key ${PRIVATE_KEY} --verify -vvvv --slow --broadcast)

run-script:; FOUNDRY_PROFILE=${network} forge script ${contract} --rpc-url ${network} --sig "run(bool, bool, bool)" ${broadcast} ${generate_diff} ${skip_timelock} -vv

run-script:; FOUNDRY_PROFILE=${network} forge script $(if $(filter zksync,${network}),--zksync) ${contract} --rpc-url ${network} --sig "run(bool, bool, bool)" ${broadcast} ${generate_diff} ${skip_timelock} -vv
4 changes: 2 additions & 2 deletions foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ evm_version = 'shanghai'
[profile.zksync.zksync]
compile = true
fallback_oz = true
mode = '3'
zksolc = '1.5.3'
optimizer_mode = 'z'
zksolc = '1.5.7'

[rpc_endpoints]
mainnet = "${RPC_MAINNET}"
Expand Down
21 changes: 16 additions & 5 deletions generator/generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,10 @@ async function askBeforeWrite(options: Options, path: string, content: string) {
export async function writeFiles(options: Options, {jsonConfig, payloads}: Files) {
const baseName = generateFolderName(options);
const baseFolder = path.join(process.cwd(), 'src/contracts/updates/', baseName);
const zkSyncBaseFolder = path.join(process.cwd(), 'zksync/src/contracts/updates', baseName);
const isZkSync = options.pools.includes('AaveV3ZkSync');

if (fs.existsSync(baseFolder)) {
if (fs.existsSync(baseFolder) || (isZkSync && fs.existsSync(zkSyncBaseFolder))) {
if (!options.force && fs.existsSync(baseFolder)) {
const force = await confirm({
message: 'A proposal already exists at that location, do you want to continue?',
Expand All @@ -79,16 +81,25 @@ export async function writeFiles(options: Options, {jsonConfig, payloads}: Files
if (!force) return;
}
} else {
fs.mkdirSync(baseFolder, {recursive: true});
if (isZkSync) {
fs.mkdirSync(zkSyncBaseFolder, {recursive: true});
}
if (!isZkSync || options.pools.length > 1) {
fs.mkdirSync(baseFolder, {recursive: true});
}
}

// write config
await askBeforeWrite(options, path.join(baseFolder, 'config.ts'), jsonConfig);
await askBeforeWrite(
options,
path.join(isZkSync ? zkSyncBaseFolder : baseFolder, 'config.ts'),
jsonConfig
);

for (const {payload, contractName} of payloads) {
for (const {pool, payload, contractName} of payloads) {
await askBeforeWrite(
options,
path.join(baseFolder, `${contractName}.sol`),
path.join(pool === 'AaveV3ZkSync' ? zkSyncBaseFolder : baseFolder, `${contractName}.sol`),
payload,
);
}
Expand Down
2 changes: 1 addition & 1 deletion generator/templates/proposal.template.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ export const proposalTemplate = (
* @title ${title || 'TODO'}
* @author ${author || 'TODO'}
* - discussion: ${discussion || 'TODO'}
* - deploy-command: make run-script contract=src/contracts/updates/${folderName}/${contractName}.sol:${contractName} network=${getChainAlias(
* - deploy-command: make run-script contract=${chain == 'ZkSync' ? 'zksync/' : ''}src/contracts/updates/${folderName}/${contractName}.sol:${contractName} network=${getChainAlias(
chain
)} broadcast=false generate_diff=true skip_timelock=false
*/
Expand Down
3 changes: 2 additions & 1 deletion generator/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ export const V3_POOLS = [
'AaveV3Base',
'AaveV3Gnosis',
'AaveV3Scroll',
'AaveV3BNB'
'AaveV3BNB',
'AaveV3ZkSync'
] as const satisfies readonly (keyof typeof addressBook)[];

export const POOLS = [
Expand Down
2 changes: 1 addition & 1 deletion generator/utils/importsResolver.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ function generateRiskStewardImport(code: string) {
const match = code.match(/RiskStewards(\w+)/);

if (match) {
imports = `import {RiskStewards${match[1]}} from '../../../../scripts/networks/RiskStewards${match[1]}.s.sol';\n`;
imports = `import {RiskStewards${match[1]}} from '${match[1] == 'ZkSync' ? '../' : ''}../../../../scripts/networks/RiskStewards${match[1]}.s.sol';\n`;
if (findMatch(code, 'IRiskSteward')) {
imports += `import {IRiskSteward${findMatch(code, 'IPriceCapAdapter') ? ', IPriceCapAdapter': ''}} from '../../../interfaces/IRiskSteward.sol';\n`;
}
Expand Down
5 changes: 2 additions & 3 deletions scripts/RiskStewardsBase.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,8 @@ abstract contract RiskStewardsBase is ProtocolV3TestBase {
vm.warp(block.timestamp + uint256(maxTimelock) + 1);
}

bool rateUpdatesPresent = rateUpdates.length != 0;
if (generateDiffReport)
createConfigurationSnapshot(pre, POOL, true, rateUpdatesPresent, false, false);
createConfigurationSnapshot(pre, POOL, true, true, false, false);

if (capUpdates.length != 0) {
callDatas[txCount] = abi.encodeWithSelector(IRiskSteward.updateCaps.selector, capUpdates);
Expand Down Expand Up @@ -175,7 +174,7 @@ abstract contract RiskStewardsBase is ProtocolV3TestBase {
}

if (generateDiffReport) {
createConfigurationSnapshot(post, POOL, true, rateUpdatesPresent, false, false);
createConfigurationSnapshot(post, POOL, true, true, false, false);
diffReports(pre, post);
}

Expand Down
11 changes: 11 additions & 0 deletions scripts/networks/RiskStewardsZkSync.s.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import {AaveV3ZkSync} from 'aave-address-book/AaveV3ZkSync.sol';
import {RiskStewardsBase} from '../RiskStewardsBase.s.sol';

abstract contract RiskStewardsZkSync is RiskStewardsBase {
constructor()
RiskStewardsBase(address(AaveV3ZkSync.POOL), AaveV3ZkSync.RISK_STEWARD)
{}
}
27 changes: 27 additions & 0 deletions zksync/src/contracts/examples/ZkSyncExample.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;

import {AaveV3ZkSyncAssets} from 'aave-address-book/AaveV3ZkSync.sol';
import {IAaveV3ConfigEngine as IEngine} from 'aave-v3-origin/src/contracts/extensions/v3-config-engine/IAaveV3ConfigEngine.sol';
import {EngineFlags} from 'aave-v3-origin/src/contracts/extensions/v3-config-engine/EngineFlags.sol';
import {RiskStewardsZkSync} from '../../../../scripts/networks/RiskStewardsZkSync.s.sol';

// make run-script network=zksync contract=zksync/src/contracts/examples/ZkSyncExample.sol broadcast=false generate_diff=true skip_timelock=false
contract ZkSyncExample is RiskStewardsZkSync {
/**
* @return string name identifier used for the diff
*/
function name() public pure override returns (string memory) {
return 'zksync_example';
}

function capsUpdates() public pure override returns (IEngine.CapsUpdate[] memory) {
IEngine.CapsUpdate[] memory capUpdates = new IEngine.CapsUpdate[](1);
capUpdates[0] = IEngine.CapsUpdate({
asset: AaveV3ZkSyncAssets.USDC_UNDERLYING,
supplyCap: 2_500_000,
borrowCap: EngineFlags.KEEP_CURRENT
});
return capUpdates;
}
}

0 comments on commit 947d6be

Please sign in to comment.