-
Notifications
You must be signed in to change notification settings - Fork 102
feat : deploy helpers for external usage #1212
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
Open
Kogaroshi
wants to merge
9
commits into
main
Choose a base branch
from
feat/lib-deploy-utils
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
d20a3a5
feat : helper functions to deploy Hub & Spoke for external codebases
Kogaroshi bec36f3
fix : add generate step in CIs
Kogaroshi bfba762
fix : fix CI
Kogaroshi 0590200
fix : fix CI
Kogaroshi 69684cd
fix : fix CI
Kogaroshi b2b6313
fix : remove new CI action
Kogaroshi 3e1596c
Merge branch 'main' of github.com:aave/aave-v4 into feat/lib-deploy-u…
Kogaroshi 7f96097
Merge branch 'main' of github.com:aave/aave-v4 into feat/lib-deploy-u…
Kogaroshi 8789f61
pull latest from main & fix logic
Kogaroshi File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| // SPDX-License-Identifier: UNLICENSED | ||
| // Copyright (c) 2025 Aave Labs | ||
| pragma solidity ^0.8.0; | ||
|
|
||
| import {Script} from 'forge-std/Script.sol'; | ||
|
|
||
| contract GenerateHubBytecodeScript is Script { | ||
| string private constant HUB_BYTECODE_PATH = 'tests/bin/hub.bytecode'; | ||
| string private constant SPOKE_INSTANCE_BYTECODE_PATH = 'tests/bin/spokeInstance.bytecode'; | ||
|
|
||
| function run() external { | ||
| bytes memory hubBytecode = vm.getCode('src/hub/instances/HubInstance.sol:HubInstance'); | ||
| vm.writeFileBinary(HUB_BYTECODE_PATH, hubBytecode); | ||
|
|
||
| string memory artifact = vm.readFile('out/SpokeInstance.sol/SpokeInstance.json'); | ||
| string memory spokeHex = vm.parseJsonString(artifact, '.bytecode.object'); | ||
|
Kogaroshi marked this conversation as resolved.
|
||
| vm.writeFile(SPOKE_INSTANCE_BYTECODE_PATH, spokeHex); | ||
|
Kogaroshi marked this conversation as resolved.
|
||
| } | ||
|
Kogaroshi marked this conversation as resolved.
|
||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,10 +1,10 @@ | ||
| { | ||
| "borrowWithSig": "222144", | ||
| "repayWithSig": "192513", | ||
| "borrowWithSig": "222132", | ||
| "repayWithSig": "192501", | ||
| "setSelfAsUserPositionManagerWithSig": "75138", | ||
| "setUsingAsCollateralWithSig": "85380", | ||
| "supplyWithSig": "155914", | ||
| "supplyWithSig": "155904", | ||
| "updateUserDynamicConfigWithSig": "63113", | ||
| "updateUserRiskPremiumWithSig": "61995", | ||
| "updateUserRiskPremiumWithSig": "62007", | ||
| "withdrawWithSig": "135124" | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| // SPDX-License-Identifier: UNLICENSED | ||
| // Copyright (c) 2025 Aave Labs | ||
| pragma solidity ^0.8.0; | ||
|
|
||
| import {Test} from 'forge-std/Test.sol'; | ||
|
|
||
| import {BytecodeLoader} from 'tests/utils/BytecodeLoader.sol'; | ||
|
|
||
| contract GenerateBytecodeScript is Test { | ||
|
Kogaroshi marked this conversation as resolved.
|
||
| string private constant HUB_BYTECODE_PATH = 'tests/bin/hub.bytecode'; | ||
| string private constant SPOKE_INSTANCE_BYTECODE_PATH = 'tests/bin/spokeInstance.bytecode'; | ||
|
Kogaroshi marked this conversation as resolved.
|
||
|
|
||
| function test_generated_HubBytecode() public view { | ||
| bytes memory hubBytecode = vm.getCode('src/hub/instances/HubInstance.sol:HubInstance'); | ||
|
|
||
| assertEq( | ||
| hubBytecode, | ||
| BytecodeLoader.loadHubBytecode(), | ||
| 'Loaded Hub bytecode does not match generated bytecode' | ||
| ); | ||
| } | ||
|
|
||
| function test_generated_SpokeInstanceBytecode() public view { | ||
| bytes memory spokeInstanceBytecode = vm.getCode( | ||
| 'src/spoke/instances/SpokeInstance.sol:SpokeInstance' | ||
| ); | ||
|
|
||
| assertEq( | ||
| spokeInstanceBytecode, | ||
| BytecodeLoader.loadSpokeInstanceBytecode(), | ||
| 'Loaded SpokeInstance bytecode does not match generated bytecode' | ||
| ); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| // SPDX-License-Identifier: UNLICENSED | ||
| // Copyright (c) 2025 Aave Labs | ||
| pragma solidity ^0.8.0; | ||
|
|
||
| import {Vm} from 'forge-std/Vm.sol'; | ||
|
|
||
| import {LiquidationLogic} from 'src/spoke/libraries/LiquidationLogic.sol'; | ||
|
|
||
| library BytecodeLoader { | ||
| Vm private constant vm = Vm(address(bytes20(uint160(uint256(keccak256('hevm cheat code')))))); | ||
|
|
||
| string private constant HUB_BYTECODE_PATH = 'tests/bin/hub.bytecode'; | ||
| string private constant SPOKE_INSTANCE_BYTECODE_PATH = 'tests/bin/spokeInstance.bytecode'; | ||
|
|
||
|
Kogaroshi marked this conversation as resolved.
|
||
| string private constant LIQUIDATION_LOGIC_PLACEHOLDER = | ||
| '__$a48140799943db40fec4e369e92a011fa5$__'; | ||
|
Kogaroshi marked this conversation as resolved.
|
||
|
|
||
| function loadHubBytecode() public view returns (bytes memory) { | ||
| return vm.readFileBinary(HUB_BYTECODE_PATH); | ||
| } | ||
|
|
||
| function loadSpokeInstanceBytecode() public view returns (bytes memory) { | ||
| string memory hexBytecode = vm.readFile(SPOKE_INSTANCE_BYTECODE_PATH); | ||
| string memory addrHex = vm.replace( | ||
| vm.toString(abi.encodePacked(address(LiquidationLogic))), | ||
| '0x', | ||
| '' | ||
| ); | ||
| string memory linked = vm.replace(hexBytecode, LIQUIDATION_LOGIC_PLACEHOLDER, addrHex); | ||
| return vm.parseBytes(linked); | ||
| } | ||
|
Kogaroshi marked this conversation as resolved.
|
||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,20 @@ | ||
| // SPDX-License-Identifier: UNLICENSED | ||
| // Copyright (c) 2025 Aave Labs | ||
| pragma solidity ^0.8.0; | ||
|
|
||
| import {BytecodeLoader} from 'tests/utils/BytecodeLoader.sol'; | ||
|
|
||
| import {Create2Utils} from 'src/deployments/utils/libraries/Create2Utils.sol'; | ||
|
|
||
| /// @notice Helper to deploy Hub from custom profile precompiled bytecode | ||
| contract DeployHub { | ||
| /// @notice Deploys a Hub contract using CREATE2 and the stored bytecode with the provided deployment arguments. | ||
| /// @param deployArgs The constructor arguments for the Hub contract, encoded as bytes. | ||
| /// @param salt The salt to use for the CREATE2 deployment, allowing for deterministic address generation. | ||
| /// @return The address of the deployed Hub contract. | ||
| function deployHub(bytes memory deployArgs, bytes32 salt) public returns (address) { | ||
| bytes memory bytecode = BytecodeLoader.loadHubBytecode(); | ||
|
|
||
| return Create2Utils.create2Deploy(salt, abi.encodePacked(bytecode, deployArgs)); | ||
| } | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,29 @@ | ||
| // SPDX-License-Identifier: UNLICENSED | ||
| // Copyright (c) 2025 Aave Labs | ||
| pragma solidity ^0.8.0; | ||
|
|
||
| import {BytecodeLoader} from 'tests/utils/BytecodeLoader.sol'; | ||
|
|
||
| import {Create2Utils} from 'src/deployments/utils/libraries/Create2Utils.sol'; | ||
|
|
||
| /// @notice Helper to deploy Spoke from custom profile precompiled bytecode | ||
| contract DeploySpoke { | ||
| /// @notice Deploys a proxified SpokeInstance contract using CREATE2 and the stored bytecode with the provided deployment arguments, and proxified using initialize arguments. | ||
| /// @param deployArgs The constructor arguments for the SpokeInstance implementation contract, encoded as bytes. | ||
| /// @param initArgs The initialization arguments for the TransparentUpgradeableProxy, encoded as bytes. | ||
| /// @param salt The salt to use for the CREATE2 deployment, allowing for deterministic address generation. | ||
| /// @return The address of the deployed SpokeInstance implementation | ||
| /// @return The address of the deployed SpokeInstance proxy | ||
| function deploySpoke( | ||
| bytes memory deployArgs, | ||
| bytes memory initArgs, | ||
| bytes32 salt | ||
| ) public returns (address, address) { | ||
| bytes memory bytecode = BytecodeLoader.loadSpokeInstanceBytecode(); | ||
|
|
||
| address impl = Create2Utils.create2Deploy(salt, abi.encodePacked(bytecode, deployArgs)); | ||
| address proxy = Create2Utils.proxify(salt, impl, msg.sender, initArgs); | ||
|
|
||
| return (impl, proxy); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.