This repository has been archived by the owner on Nov 27, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
309 additions
and
311 deletions.
There are no files selected for viewing
This file contains 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 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,70 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity 0.8.23; | ||
|
||
import {Script, stdJson} from "forge-std/Script.sol"; | ||
|
||
import {DeployUtils} from "script/DeployUtils.sol"; | ||
|
||
import {LlamaAccountMulticallExtension} from "src/account-multicall/LlamaAccountMulticallExtension.sol"; | ||
import {LlamaAccountMulticallGuard} from "src/account-multicall/LlamaAccountMulticallGuard.sol"; | ||
import {LlamaAccountMulticallStorage} from "src/account-multicall/LlamaAccountMulticallStorage.sol"; | ||
|
||
contract DeployLlamaAccountMulticall is Script { | ||
using stdJson for string; | ||
|
||
struct TargetSelectorAuthorizationInputs { | ||
// Attributes need to be in alphabetical order so JSON decodes properly. | ||
string comment; | ||
bytes selector; | ||
address target; | ||
} | ||
|
||
// Account multicall contracts. | ||
LlamaAccountMulticallStorage accountMulticallStorage; | ||
LlamaAccountMulticallExtension accountMulticallExtension; | ||
LlamaAccountMulticallGuard accountMulticallGuard; | ||
|
||
function run(string memory configFile) public { | ||
string memory jsonInput = DeployUtils.readScriptInput(configFile); | ||
|
||
address llamaExecutor = jsonInput.readAddress(".llamaExecutor"); | ||
LlamaAccountMulticallStorage.TargetSelectorAuthorization[] memory data = readTargetSelectorAuthorizations(jsonInput); | ||
|
||
DeployUtils.print(string.concat("Deploying Llama rewards claimer contracts to chain:", vm.toString(block.chainid))); | ||
|
||
vm.broadcast(); | ||
accountMulticallStorage = new LlamaAccountMulticallStorage(llamaExecutor, data); | ||
DeployUtils.print(string.concat(" LlamaAccountMulticallStorage: ", vm.toString(address(accountMulticallStorage)))); | ||
|
||
vm.broadcast(); | ||
accountMulticallExtension = new LlamaAccountMulticallExtension(accountMulticallStorage); | ||
DeployUtils.print( | ||
string.concat(" LlamaAccountMulticallExtension: ", vm.toString(address(accountMulticallExtension))) | ||
); | ||
|
||
vm.broadcast(); | ||
accountMulticallGuard = new LlamaAccountMulticallGuard(accountMulticallExtension); | ||
DeployUtils.print(string.concat(" LlamaAccountMulticallGuard: ", vm.toString(address(accountMulticallGuard)))); | ||
} | ||
|
||
function readTargetSelectorAuthorizations(string memory jsonInput) | ||
internal | ||
pure | ||
returns (LlamaAccountMulticallStorage.TargetSelectorAuthorization[] memory) | ||
{ | ||
bytes memory data = jsonInput.parseRaw(".initialTargetSelectorAuthorizations"); | ||
|
||
TargetSelectorAuthorizationInputs[] memory rawConfigs = abi.decode(data, (TargetSelectorAuthorizationInputs[])); | ||
|
||
LlamaAccountMulticallStorage.TargetSelectorAuthorization[] memory configs = | ||
new LlamaAccountMulticallStorage.TargetSelectorAuthorization[](rawConfigs.length); | ||
|
||
for (uint256 i = 0; i < rawConfigs.length; i++) { | ||
configs[i].target = rawConfigs[i].target; | ||
configs[i].selector = bytes4(rawConfigs[i].selector); | ||
configs[i].isAuthorized = true; | ||
} | ||
|
||
return configs; | ||
} | ||
} |
This file was deleted.
Oops, something went wrong.
2 changes: 1 addition & 1 deletion
2
script/input/1/mockRewardsClaimerConfig.json → ...t/input/1/mockAccountMulticallConfig.json
This file contains 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
2 changes: 1 addition & 1 deletion
2
.../input/11155111/rewardsClaimerConfig.json → ...nput/11155111/accountMulticallConfig.json
This file contains 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 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,15 +1,15 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity 0.8.23; | ||
|
||
import {LlamaAccountMulticallStorage} from "src/account-multicall/LlamaAccountMulticallStorage.sol"; | ||
import {LlamaBaseAccountExtension} from "src/common/LlamaBaseAccountExtension.sol"; | ||
import {LlamaUtils} from "src/lib/LlamaUtils.sol"; | ||
import {LlamaRewardsClaimStorage} from "src/rewards-claimer/LlamaRewardsClaimStorage.sol"; | ||
|
||
/// @title Llama Rewards Claim Account Extension | ||
/// @title Llama Account Multicall Extension | ||
/// @author Llama ([email protected]) | ||
/// @notice An account extension that claims rewards on behalf of the Llama account. | ||
/// @notice An account extension that can multicall on behalf of the Llama account. | ||
/// @dev This contract should be delegate-called from a Llama account. | ||
contract LlamaRewardsClaimAccountExtension is LlamaBaseAccountExtension { | ||
contract LlamaAccountMulticallExtension is LlamaBaseAccountExtension { | ||
/// @dev Struct to hold target data. | ||
struct TargetData { | ||
address target; // The target contract. | ||
|
@@ -25,18 +25,18 @@ contract LlamaRewardsClaimAccountExtension is LlamaBaseAccountExtension { | |
/// @dev Thrown if the target-selector is not authorized. | ||
error UnauthorizedTargetSelector(address target, bytes4 selector); | ||
|
||
/// @notice The rewards claim storage contract. | ||
LlamaRewardsClaimStorage public immutable REWARDS_CLAIM_STORAGE; | ||
/// @notice The Llama account multicall storage contract. | ||
LlamaAccountMulticallStorage public immutable ACCOUNT_MULTICALL_STORAGE; | ||
|
||
/// @dev Initializes the Llama rewards claim account extenstion. | ||
constructor(LlamaRewardsClaimStorage rewardsClaimStorage) { | ||
REWARDS_CLAIM_STORAGE = rewardsClaimStorage; | ||
/// @dev Initializes the Llama account multicall extenstion. | ||
constructor(LlamaAccountMulticallStorage accountMulticallStorage) { | ||
ACCOUNT_MULTICALL_STORAGE = accountMulticallStorage; | ||
} | ||
|
||
/// @notice Claims rewards from the target contracts. | ||
/// @param targetData The target data to claim rewards from. | ||
/// @notice Multicalls on behalf of the Llama account. | ||
/// @param targetData The target data to multicall. | ||
/// @return returnData The return data from the target calls. | ||
function claimRewards(TargetData[] memory targetData) external onlyDelegateCall returns (bytes[] memory returnData) { | ||
function multicall(TargetData[] memory targetData) external onlyDelegateCall returns (bytes[] memory returnData) { | ||
uint256 length = targetData.length; | ||
returnData = new bytes[](length); | ||
for (uint256 i = 0; i < length; i = LlamaUtils.uncheckedIncrement(i)) { | ||
|
@@ -46,7 +46,7 @@ contract LlamaRewardsClaimAccountExtension is LlamaBaseAccountExtension { | |
bytes4 selector = bytes4(callData); | ||
|
||
// Check if the target-selector is authorized. | ||
if (!REWARDS_CLAIM_STORAGE.authorizedTargetSelectors(target, selector)) { | ||
if (!ACCOUNT_MULTICALL_STORAGE.authorizedTargetSelectors(target, selector)) { | ||
revert UnauthorizedTargetSelector(target, selector); | ||
} | ||
|
||
|
This file contains 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,24 +1,24 @@ | ||
// SPDX-License-Identifier: MIT | ||
pragma solidity 0.8.23; | ||
|
||
import {LlamaAccountMulticallExtension} from "src/account-multicall/LlamaAccountMulticallExtension.sol"; | ||
import {ILlamaActionGuard} from "src/interfaces/ILlamaActionGuard.sol"; | ||
import {ActionInfo} from "src/lib/Structs.sol"; | ||
import {LlamaRewardsClaimAccountExtension} from "src/rewards-claimer/LlamaRewardsClaimAccountExtension.sol"; | ||
|
||
/// @title Llama Rewards Claim Guard | ||
/// @title Llama Account Multicall Guard | ||
/// @author Llama ([email protected]) | ||
/// @notice A guard that only allows the `LlamaRewardsClaimAccountExtension.claimRewards` to be delegate-called | ||
/// @notice A guard that only allows the `LlamaAccountMulticallExtension.multicall` to be delegate-called | ||
/// @dev This guard should be used to protect the `execute` function in the `LlamaAccount` contract | ||
contract LlamaRewardsClaimGuard is ILlamaActionGuard { | ||
contract LlamaAccountMulticallGuard is ILlamaActionGuard { | ||
/// @dev Thrown if the call is not authorized. | ||
error UnauthorizedCall(address target, bytes4 selector, bool withDelegatecall); | ||
|
||
/// @notice The address of the `RewardsClaimer` account extension. | ||
LlamaRewardsClaimAccountExtension public immutable REWARDS_CLAIMER; | ||
/// @notice The address of the Llama account multicall extension. | ||
LlamaAccountMulticallExtension public immutable ACCOUNT_MULTICALL_EXTENSION; | ||
|
||
/// @dev Initializes the Llama rewards claim guard. | ||
constructor(LlamaRewardsClaimAccountExtension rewardsClaimer) { | ||
REWARDS_CLAIMER = rewardsClaimer; | ||
/// @dev Initializes the Llama account multicall guard. | ||
constructor(LlamaAccountMulticallExtension accountMulticallExtension) { | ||
ACCOUNT_MULTICALL_EXTENSION = accountMulticallExtension; | ||
} | ||
|
||
/// @inheritdoc ILlamaActionGuard | ||
|
@@ -28,9 +28,10 @@ contract LlamaRewardsClaimGuard is ILlamaActionGuard { | |
abi.decode(actionInfo.data[4:], (address, bool, uint256, bytes)); | ||
bytes4 selector = bytes4(data); | ||
|
||
// Check if the target is the rewards claimer, selector is `claimRewards` and the call type is a delegatecall. | ||
// Check if the target is the Llama account multicall extension, selector is `multicall` and the call type is a | ||
// delegatecall. | ||
if ( | ||
target != address(REWARDS_CLAIMER) || selector != LlamaRewardsClaimAccountExtension.claimRewards.selector | ||
target != address(ACCOUNT_MULTICALL_EXTENSION) || selector != LlamaAccountMulticallExtension.multicall.selector | ||
|| !withDelegatecall | ||
) revert UnauthorizedCall(target, selector, withDelegatecall); | ||
} | ||
|
This file contains 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 |
---|---|---|
|
@@ -3,11 +3,11 @@ pragma solidity 0.8.23; | |
|
||
import {LlamaUtils} from "src/lib/LlamaUtils.sol"; | ||
|
||
/// @title Llama Rewards Claim Storage | ||
/// @title Llama Account Multicall Storage | ||
/// @author Llama ([email protected]) | ||
/// @notice The storage contract for the `LlamaRewardsClaimAccountExtension` contract. | ||
/// @notice The storage contract for the `LlamaAccountMulticallExtension` contract. | ||
/// @dev This is a separate storage contract to prevent storage collisions with the Llama account. | ||
contract LlamaRewardsClaimStorage { | ||
contract LlamaAccountMulticallStorage { | ||
/// @dev Struct to hold authorized target-selectors. | ||
struct TargetSelectorAuthorization { | ||
address target; // The target contract. | ||
|
@@ -27,7 +27,7 @@ contract LlamaRewardsClaimStorage { | |
/// @notice Mapping of all authorized target-selectors. | ||
mapping(address target => mapping(bytes4 selector => bool isAuthorized)) public authorizedTargetSelectors; | ||
|
||
/// @dev Initializes the Llama rewards claim storage. | ||
/// @dev Initializes the Llama account multicall storage. | ||
constructor(address llamaExecutor, TargetSelectorAuthorization[] memory data) { | ||
LLAMA_EXECUTOR = llamaExecutor; | ||
_setAuthorizedTargetSelectors(data); | ||
|
This file contains 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
Oops, something went wrong.