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
13 changes: 13 additions & 0 deletions scripts/deploy/AaveV4DeployBatchBase.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ abstract contract AaveV4DeployBatchBaseScript is Script {
_logNativeTokenGateway(inputs);
_logSignatureGateway(inputs);
_logPositionManagers(inputs);
_logTokenizationSpokeBeacon(inputs);
_logRoles(inputs);
_appendSummary('--------------------------------------------------');

Expand Down Expand Up @@ -144,6 +145,10 @@ abstract contract AaveV4DeployBatchBaseScript is Script {
_logWarning(string.concat('position manager owner', message, outcome));
sanitizedInputs.positionManagerOwner = deployer;
}
if (inputs.deployTokenizationSpokeBeacon && inputs.tokenizationSpokeBeaconOwner == address(0)) {
_logWarning(string.concat('tokenization spoke beacon owner', message, outcome));
sanitizedInputs.tokenizationSpokeBeaconOwner = deployer;
}
if (inputs.salt == bytes32(0)) {
_logWarning('salt is zero');
}
Expand Down Expand Up @@ -199,6 +204,14 @@ abstract contract AaveV4DeployBatchBaseScript is Script {
}
}

function _logTokenizationSpokeBeacon(InputUtils.FullDeployInputs memory inputs) internal {
if (inputs.deployTokenizationSpokeBeacon) {
_appendSummary('tokenizationSpoke beacon + implementation will be deployed');
} else {
_appendSummary('tokenizationSpoke beacon: skipped (deployTokenizationSpokeBeacon is false)');
}
}

function _logRoles(InputUtils.FullDeployInputs memory inputs) internal {
if (inputs.grantRoles) {
_appendSummary('roles: will be granted during deployment');
Expand Down
2 changes: 2 additions & 0 deletions scripts/deploy/examples/AaveV4DeployAnvil.s.sol
Original file line number Diff line number Diff line change
Expand Up @@ -49,10 +49,12 @@ contract AaveV4DeployAnvil is AaveV4DeployBatchBaseScript {
spokeConfiguratorAdmin: address(1),
gatewayOwner: address(2),
positionManagerOwner: address(3),
tokenizationSpokeBeaconOwner: address(4),
nativeWrapper: weth,
deployNativeTokenGateway: true,
deploySignatureGateway: true,
deployPositionManagers: true,
deployTokenizationSpokeBeacon: true,
grantRoles: true,
hubLabels: hubLabels,
spokeLabels: spokeLabels,
Expand Down
30 changes: 15 additions & 15 deletions snapshots/TokenizationSpoke.Operations.json
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
{
"deposit": "118614",
"depositWithSig": "129518",
"mint": "118251",
"mintWithSig": "129130",
"permit": "62766",
"redeem: on behalf, full": "95212",
"redeem: on behalf, partial": "119015",
"redeem: self, full": "94282",
"redeem: self, partial": "113482",
"redeemWithSig": "128864",
"withdraw: on behalf, full": "95646",
"withdraw: on behalf, partial": "119557",
"withdraw: self, full": "94824",
"withdraw: self, partial": "114024",
"withdrawWithSig": "129405"
"deposit": "128151",
"depositWithSig": "139020",
"mint": "127788",
"mintWithSig": "138620",
"permit": "65752",
"redeem: on behalf, full": "102440",
"redeem: on behalf, partial": "126440",
"redeem: self, full": "101707",
"redeem: self, partial": "120907",
"redeemWithSig": "136245",
"withdraw: on behalf, full": "102993",
"withdraw: on behalf, partial": "126993",
"withdraw: self, full": "102260",
"withdraw: self, partial": "121460",
"withdrawWithSig": "136821"
}
22 changes: 11 additions & 11 deletions src/config-engine/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,17 @@ The four groups, and the virtual functions in each, are listed below.

#### Hub actions (`_executeHubActions`)

| Function | Struct | Purpose |
| ----------------------------- | ----------------------- | ----------------------------------------------------------------------------------------------------- |
| `hubAssetListings()` | `AssetListing` | List a new asset on a Hub. Optionally deploys a TokenizationSpoke if `symbol` `and name` are defined. |
| `hubAssetConfigUpdates()` | `AssetConfigUpdate` | Update fee config, IR strategy/data, reinvestment controller |
| `hubSpokeToAssetsAdditions()` | `SpokeToAssetsAddition` | Register a Spoke for multiple assets |
| `hubSpokeConfigUpdates()` | `SpokeConfigUpdate` | Update Spoke caps, risk premium threshold, active/halted |
| `hubAssetHalts()` | `AssetHalt` | Halt an asset |
| `hubAssetDeactivations()` | `AssetDeactivation` | Deactivate an asset |
| `hubAssetCapsResets()` | `AssetCapsReset` | Reset asset caps |
| `hubSpokeDeactivations()` | `SpokeDeactivation` | Deactivate a Spoke |
| `hubSpokeCapsResets()` | `SpokeCapsReset` | Reset Spoke caps |
| Function | Struct | Purpose |
| ----------------------------- | ----------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------ |
| `hubAssetListings()` | `AssetListing` | List a new asset on a Hub. Optionally deploys a TokenizationSpoke beacon proxy (pointing to `tokenization.beacon`) if `symbol` `and name` are defined. |
| `hubAssetConfigUpdates()` | `AssetConfigUpdate` | Update fee config, IR strategy/data, reinvestment controller |
| `hubSpokeToAssetsAdditions()` | `SpokeToAssetsAddition` | Register a Spoke for multiple assets |
| `hubSpokeConfigUpdates()` | `SpokeConfigUpdate` | Update Spoke caps, risk premium threshold, active/halted |
| `hubAssetHalts()` | `AssetHalt` | Halt an asset |
| `hubAssetDeactivations()` | `AssetDeactivation` | Deactivate an asset |
| `hubAssetCapsResets()` | `AssetCapsReset` | Reset asset caps |
| `hubSpokeDeactivations()` | `SpokeDeactivation` | Deactivate a Spoke |
| `hubSpokeCapsResets()` | `SpokeCapsReset` | Reset Spoke caps |

#### Spoke actions (`_executeSpokeActions`)

Expand Down
2 changes: 2 additions & 0 deletions src/config-engine/interfaces/IAaveV4ConfigEngine.sol
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,12 @@ import {IAssetInterestRateStrategy} from 'src/hub/interfaces/IAssetInterestRateS
/// the universal KEEP_CURRENT sentinel. Boolean fields use uint256 (0=false, 1=true, KEEP_CURRENT=skip).
interface IAaveV4ConfigEngine {
/// @notice Parameters for tokenization of an asset on a Hub when listing the asset.
/// @dev beacon The shared TokenizationSpoke beacon the deployed proxy points to.
/// @dev addCap The add cap for the TokenizationSpoke (0 means no tokenization).
/// @dev name The name for the TokenizationSpoke.
/// @dev symbol The symbol for the TokenizationSpoke.
struct TokenizationSpokeConfig {
address beacon;

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this be here or should as we add it as an immutable in hubEngine and it's non configurable? in the config engine or helpers we can abstract this by pulling from address-book (v3 takes the former approach)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If the goal is to have 1 beacon per chain, should be an immutable in the Hub Engine, shouldn't allow to pass it to avoid mistakes.
If we want 1 beacon per market (for example between current one, and a whitelabel one or Horizon), then we should leave it configurable, or derived from the HubConfigurator managing a specific instance

uint256 addCap;
string name;
string symbol;
Expand Down
1 change: 1 addition & 0 deletions src/config-engine/libraries/HubEngine.sol
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,7 @@ library HubEngine {
}

address proxy = TokenizationSpokeDeployer.deploy(
listing.tokenization.beacon,
listing.hub,
listing.underlying,
listing.tokenization.name,
Expand Down
93 changes: 27 additions & 66 deletions src/config-engine/libraries/TokenizationSpokeDeployer.sol
Original file line number Diff line number Diff line change
@@ -1,114 +1,75 @@
// SPDX-License-Identifier: LicenseRef-BUSL
pragma solidity ^0.8.0;

import {TransparentUpgradeableProxy} from 'src/dependencies/openzeppelin/TransparentUpgradeableProxy.sol';
import {BeaconProxy} from 'src/dependencies/openzeppelin/BeaconProxy.sol';
import {Create2Utils} from 'src/deployments/utils/libraries/Create2Utils.sol';
import {TokenizationSpokeInstance} from 'src/spoke/instances/TokenizationSpokeInstance.sol';
import {ITokenizationSpokeInstance} from 'src/deployments/utils/interfaces/ITokenizationSpokeInstance.sol';

/// @title TokenizationSpokeDeployer
/// @author Aave Labs
/// @notice Library for deterministic CREATE2 deployment and address pre-computation of TokenizationSpoke proxies
/// using the Safe Singleton Factory.
/// @notice Library for deterministic CREATE2 deployment and address pre-computation of TokenizationSpoke
/// beacon proxies using the Safe Singleton Factory.
library TokenizationSpokeDeployer {
/// @notice Deploys a TokenizationSpokeInstance implementation and TransparentUpgradeableProxy via CREATE2
/// through the Safe Singleton Factory.
/// @dev The proxy admin owner is set to `msg.sender`.
/// @notice Deploys a TokenizationSpoke BeaconProxy via CREATE2 through the Safe Singleton Factory.
/// @dev The proxy points to the shared `beacon`, whose owner controls the implementation upgrades.
/// @param beacon The address of the shared TokenizationSpoke beacon.
/// @param hub The address of the Hub.
/// @param underlying The address of the underlying asset.
/// @param name The ERC20 name for the TokenizationSpoke share token.
/// @param symbol The ERC20 symbol for the TokenizationSpoke share token.
/// @return proxy The address of the deployed proxy.
function deploy(
address beacon,
address hub,
address underlying,
string calldata name,
string calldata symbol
) external returns (address proxy) {
bytes32 implSalt = _computeImplementationSalt(hub, underlying, name, symbol);
bytes memory implCreationCode = abi.encodePacked(
type(TokenizationSpokeInstance).creationCode,
abi.encode(hub, underlying)
bytes32 proxySalt = _computeProxySalt(beacon, hub, underlying, name, symbol);
bytes memory initData = abi.encodeCall(
ITokenizationSpokeInstance.initialize,
(hub, underlying, name, symbol)
);
address impl = Create2Utils.create2Deploy(implSalt, implCreationCode);

bytes32 proxySalt = _computeProxySalt(hub, underlying, name, symbol);
bytes memory initData = abi.encodeCall(TokenizationSpokeInstance.initialize, (name, symbol));
bytes memory proxyCreationCode = abi.encodePacked(
type(TransparentUpgradeableProxy).creationCode,
abi.encode(impl, msg.sender, initData)
type(BeaconProxy).creationCode,
abi.encode(beacon, initData)
);
proxy = Create2Utils.create2Deploy(proxySalt, proxyCreationCode);
}

/// @notice Pre-computes the CREATE2 address of the TokenizationSpokeInstance implementation.
/// @notice Pre-computes the CREATE2 address of the TokenizationSpoke BeaconProxy.
/// @param beacon The address of the shared TokenizationSpoke beacon.
/// @param hub The address of the Hub.
/// @param underlying The address of the underlying asset.
/// @param name The ERC20 name for the TokenizationSpoke share token.
/// @param symbol The ERC20 symbol for the TokenizationSpoke share token.
/// @return The predicted implementation address.
function computeImplementationAddress(
address hub,
address underlying,
string memory name,
string memory symbol
) external pure returns (address) {
return _computeImplementationAddress(hub, underlying, name, symbol);
}

/// @notice Pre-computes the CREATE2 address of the TransparentUpgradeableProxy.
/// @param hub The address of the Hub.
/// @param underlying The address of the underlying asset.
/// @param name The ERC20 name for the TokenizationSpoke share token.
/// @param symbol The ERC20 symbol for the TokenizationSpoke share token.
/// @param proxyAdminOwner The initial owner of the ProxyAdmin (msg.sender in `deploy`).
/// @return The predicted proxy address.
function computeProxyAddress(
address beacon,
address hub,
address underlying,
string memory name,
string memory symbol,
address proxyAdminOwner
string memory symbol
) external pure returns (address) {
address impl = _computeImplementationAddress(hub, underlying, name, symbol);

bytes32 proxySalt = _computeProxySalt(hub, underlying, name, symbol);
bytes memory initData = abi.encodeCall(TokenizationSpokeInstance.initialize, (name, symbol));
bytes memory creationCode = abi.encodePacked(
type(TransparentUpgradeableProxy).creationCode,
abi.encode(impl, proxyAdminOwner, initData)
bytes32 proxySalt = _computeProxySalt(beacon, hub, underlying, name, symbol);
bytes memory initData = abi.encodeCall(
ITokenizationSpokeInstance.initialize,
(hub, underlying, name, symbol)
);
return Create2Utils.computeCreate2Address(proxySalt, creationCode);
}

function _computeImplementationAddress(
address hub,
address underlying,
string memory name,
string memory symbol
) internal pure returns (address) {
bytes32 implSalt = _computeImplementationSalt(hub, underlying, name, symbol);
bytes memory creationCode = abi.encodePacked(
type(TokenizationSpokeInstance).creationCode,
abi.encode(hub, underlying)
type(BeaconProxy).creationCode,
abi.encode(beacon, initData)
);
return Create2Utils.computeCreate2Address(implSalt, creationCode);
}

function _computeImplementationSalt(
address hub,
address underlying,
string memory name,
string memory symbol
) internal pure returns (bytes32) {
return keccak256(abi.encode(hub, underlying, name, symbol, 'impl'));
return Create2Utils.computeCreate2Address(proxySalt, creationCode);
}

function _computeProxySalt(
address beacon,
address hub,
address underlying,
string memory name,
string memory symbol
) internal pure returns (bytes32) {
return keccak256(abi.encode(hub, underlying, name, symbol, 'proxy'));
return keccak256(abi.encode(beacon, hub, underlying, name, symbol, 'proxy'));
}
}
57 changes: 57 additions & 0 deletions src/dependencies/openzeppelin/BeaconProxy.sol
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// SPDX-License-Identifier: MIT
// OpenZeppelin Contracts (last updated v5.2.0) (proxy/beacon/BeaconProxy.sol)

pragma solidity ^0.8.22;

import {IBeacon} from "./IBeacon.sol";
import {Proxy} from "./Proxy.sol";
import {ERC1967Utils} from "./ERC1967Utils.sol";

/**
* @dev This contract implements a proxy that gets the implementation address for each call from an {UpgradeableBeacon}.
*
* The beacon address can only be set once during construction, and cannot be changed afterwards. It is stored in an
* immutable variable to avoid unnecessary storage reads, and also in the beacon storage slot specified by
* https://eips.ethereum.org/EIPS/eip-1967[ERC-1967] so that it can be accessed externally.
*
* CAUTION: Since the beacon address can never be changed, you must ensure that you either control the beacon, or trust
* the beacon to not upgrade the implementation maliciously.
*
* IMPORTANT: Do not use the implementation logic to modify the beacon storage slot. Doing so would leave the proxy in
* an inconsistent state where the beacon storage slot does not match the beacon address.
*/
contract BeaconProxy is Proxy {
// An immutable address for the beacon to avoid unnecessary SLOADs before each delegate call.
address private immutable _beacon;

/**
* @dev Initializes the proxy with `beacon`.
*
* If `data` is nonempty, it's used as data in a delegate call to the implementation returned by the beacon. This
* will typically be an encoded function call, and allows initializing the storage of the proxy like a Solidity
* constructor.
*
* Requirements:
*
* - `beacon` must be a contract with the interface {IBeacon}.
* - If `data` is empty, `msg.value` must be zero.
*/
constructor(address beacon, bytes memory data) payable {
ERC1967Utils.upgradeBeaconToAndCall(beacon, data);
_beacon = beacon;
}

/**
* @dev Returns the current implementation address of the associated beacon.
*/
function _implementation() internal view virtual override returns (address) {
return IBeacon(_getBeacon()).implementation();
}

/**
* @dev Returns the beacon.
*/
function _getBeacon() internal view virtual returns (address) {
return _beacon;
}
}
Loading
Loading