Skip to content

Commit

Permalink
feat: discussion feedback (#1)
Browse files Browse the repository at this point in the history
fix: move date
  • Loading branch information
sakulstra committed Dec 3, 2024
1 parent 098ddc7 commit c7b299f
Show file tree
Hide file tree
Showing 9 changed files with 234 additions and 64 deletions.
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
RPC_MAINNET=
117 changes: 117 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
Business Source License 1.1

License text copyright (c) 2020 MariaDB Corporation Ab, All Rights Reserved.
“Business Source License” is a trademark of MariaDB Corporation Ab.

---

Parameters

Licensor: Aave DAO, represented by its governance smart contracts

Licensed Work: GhoDirectMinter
The Licensed Work is (c) 2024 Aave DAO, represented by its governance smart contracts

Additional Use Grant: You are permitted to use, copy, and modify the Licensed Work, subject to
the following conditions:

- Your use of the Licensed Work shall not, directly or indirectly, enable, facilitate,
or assist in any way with the migration of users and/or funds from the Aave ecosystem.
The "Aave ecosystem" is defined in the context of this License as the collection of
software protocols and applications approved by the Aave governance, including all
those produced within compensated service provider engagements with the Aave DAO.
The Aave DAO is able to waive this requirement for one or more third-parties, if and
only if explicitly indicating it on a record 'authorizations' on staketoken.aavelicense.eth.
- You are neither an individual nor a direct or indirect participant in any incorporated
organization, DAO, or identifiable group, that has deployed in production any original
or derived software ("fork") of the Aave ecosystem for purposes competitive to Aave,
within the preceding two years.
The Aave DAO is able to waive this requirement for one or more third-parties, if and
only if explicitly indicating it on a record 'authorizations' on staketoken.aavelicense.eth.
- You must ensure that the usage of the Licensed Work does not result in any direct or
indirect harm to the Aave ecosystem or the Aave brand. This encompasses, but is not limited to,
reputational damage, omission of proper credit/attribution, or utilization for any malicious
intent.

Change Date: The earlier of:
- 2028-12-03
- The date specified in the 'change-date' record on gho-direct-minter.aavelicense.eth

Change License: MIT

---

Notice

The Business Source License (this document, or the “License”) is not an Open
Source license. However, the Licensed Work will eventually be made available
under an Open Source License, as stated in this License.

---

Terms

The Licensor hereby grants you the right to copy, modify, create derivative
works, redistribute, and make non-production use of the Licensed Work. The
Licensor may make an Additional Use Grant, above, permitting limited
production use.

Effective on the Change Date, or the fourth anniversary of the first publicly
available distribution of a specific version of the Licensed Work under this
License, whichever comes first, the Licensor hereby grants you rights under
the terms of the Change License, and the rights granted in the paragraph
above terminate.

If your use of the Licensed Work does not comply with the requirements
currently in effect as described in this License, you must purchase a
commercial license from the Licensor, its affiliated entities, or authorized
resellers, or you must refrain from using the Licensed Work.

All copies of the original and modified Licensed Work, and derivative works
of the Licensed Work, are subject to this License. This License applies
separately for each version of the Licensed Work and the Change Date may vary
for each version of the Licensed Work released by Licensor.

You must conspicuously display this License on each original or modified copy
of the Licensed Work. If you receive the Licensed Work in original or
modified form from a third party, the terms and conditions set forth in this
License apply to your use of that work.

Any use of the Licensed Work in violation of this License will automatically
terminate your rights under this License for the current and all other
versions of the Licensed Work.

This License does not grant you any right in any trademark or logo of
Licensor or its affiliates (provided that you may use a trademark or logo of
Licensor as expressly required by this License).

TO THE EXTENT PERMITTED BY APPLICABLE LAW, THE LICENSED WORK IS PROVIDED ON
AN “AS IS” BASIS. LICENSOR HEREBY DISCLAIMS ALL WARRANTIES AND CONDITIONS,
EXPRESS OR IMPLIED, INCLUDING (WITHOUT LIMITATION) WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT, AND
TITLE.

MariaDB hereby grants you permission to use this License’s text to license
your works, and to refer to it using the trademark “Business Source License”,
as long as you comply with the Covenants of Licensor below.

Covenants of Licensor

In consideration of the right to use this License’s text and the “Business
Source License” name and trademark, Licensor covenants to MariaDB, and to all
other recipients of the licensed work to be provided by Licensor:

1. To specify as the Change License the GPL Version 2.0 or any later version,
or a license that is compatible with GPL Version 2.0 or a later version,
where “compatible” means that software provided under the Change License can
be included in a program with software provided under GPL Version 2.0 or a
later version. Licensor may specify additional Change Licenses without
limitation.

2. To either: (a) specify an additional grant of rights to use that does not
impose any additional restriction on the right granted in this License, as
the Additional Use Grant; or (b) insert the text “None”.

3. To specify a Change Date.

4. Not to modify this License in any other way.
52 changes: 50 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,51 @@
## GHODirectMinter
## GhoDirectMinter

The GHO direct minter is a facilitator that can **mint and supply** and **withdraw and burn** GHO tokens from a configured aave pool.
The GHO direct minter is a generic facilitator that can inject GHO into an aave pool.

### Summary

The `GhoDirectMinter` is a smart contract that can be used to mint & burn GHO directly into/from an Aave pool.
In order to mint GHO the `GhoDirectMinter` will need to be registered as a `Facilitator` in the GHO contract.

This repository contains two contracts:

- [`GhoDirectMinter`](./src/GhoDirectMinter.sol) which contains the actual Facilitator
- [`LidoGHOListing`](./src/proposals/LidoGHOListing.sol) which is a reference implementation of a proposal to 1) list GHO on Aave Lido instance and 2) deploy and active a `GhoDirectMinter` facilitator.

### Specification

**Prerequisites:**

- the pool targeted by the `GhoDirectMinter` must have GHO listed as a reserve.
- the GHO AToken and VariableDebtToken implementations must not deviate from the Aave standard implementation.
- the `GhoDirectMinter` must be registered as a `Facilitator` with a non zero bucket capacity.
- the `GhoDirectMinter` must obtain the `RISK_ADMIN_ROLE` in order to supply GHO to the pool.

The `GhoDirectMinter` offers the following functions:

- `mintAndSupply` which allows a permissioned entity to mint GHO and supply it to the pool.
- `withdrawAndBurn` which allows a permissioned entity to withdraw GHO from the pool and burn it.
- `transferExcessToTreasury` which allows the permissionless transfer of the accrued fee to the collector.

While default permissioned entity is the owner(likely the governance short executor), but the contract inherits from [UpgradeableOwnableWithGuardian](https://github.com/bgd-labs/solidity-utils/blob/main/src/contracts/access-control/UpgradeableOwnableWithGuardian.sol) which allows to share permissions with another party (e.g. the GHO stewards).

### Risk considerations

The `GhoDirectMinter` can only inject and remove available GHO from the pool.
The actual maximum exposure of the reserve is managed via the `BucketSize` and the chosen `borrow cap`.

## Development

This project uses [Foundry](https://getfoundry.sh). See the [book](https://book.getfoundry.sh/getting-started/installation.html) for detailed instructions on how to install and use Foundry.

## Setup

```sh
forge install
```

## Test

```sh
forge test
```
1 change: 0 additions & 1 deletion foundry.toml
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,5 @@ zksync = "${RPC_ZKSYNC}"
[etherscan]
mainnet = { key = "${ETHERSCAN_API_KEY_MAINNET}", chain = 1 }


[fmt]
tab_width = 2
37 changes: 23 additions & 14 deletions src/GHODirectMinter.sol → src/GhoDirectMinter.sol
Original file line number Diff line number Diff line change
Expand Up @@ -2,38 +2,41 @@
pragma solidity ^0.8.0;

import {IPool, DataTypes} from "aave-v3-origin/contracts/interfaces/IPool.sol";
import {OwnableUpgradeable} from "openzeppelin-contracts-upgradeable/contracts/access/OwnableUpgradeable.sol";
import {IPoolAddressesProvider} from "aave-v3-origin/contracts/interfaces/IPoolAddressesProvider.sol";
import {IPoolConfigurator} from "aave-v3-origin/contracts/interfaces/IPoolConfigurator.sol";
import {ReserveConfiguration} from "aave-v3-origin/contracts/protocol/libraries/configuration/ReserveConfiguration.sol";
import {Initializable} from "openzeppelin-contracts-upgradeable/contracts/proxy/utils/Initializable.sol";
import {IERC20} from "solidity-utils/contracts/oz-common/interfaces/IERC20.sol";
import {SafeERC20} from "solidity-utils/contracts/oz-common/SafeERC20.sol";
import {UpgradeableOwnableWithGuardian} from
"solidity-utils/contracts/access-control/UpgradeableOwnableWithGuardian.sol";
import {IGhoToken} from "./interfaces/IGhoToken.sol";
import {IGHODirectMinter} from "./interfaces/IGHODirectMinter.sol";
import {RiskCouncilControlled} from "./RiskCouncilControlled.sol";
import {IGhoDirectMinter} from "./interfaces/IGhoDirectMinter.sol";

/**
* @title GHODirectMinter
* @title GhoDirectMinter
* @notice The GHODirectMinter is a GHO facilitator, that can inject(mint) and remove(burn) GHO from an AAVE pool that has GHO listed as a non-custom AToken.
* @author BGD Labs @bgdlabs
*/
contract GHODirectMinter is Initializable, OwnableUpgradeable, IGHODirectMinter, RiskCouncilControlled {
contract GhoDirectMinter is Initializable, UpgradeableOwnableWithGuardian, IGhoDirectMinter {
using ReserveConfiguration for DataTypes.ReserveConfigurationMap;
using SafeERC20 for IERC20;

// @inheritdoc IGHODirectMinter
IPool public immutable POOL;
// @inheritdoc IGHODirectMinter
IPoolConfigurator public immutable POOL_CONFIGURATOR;
// @inheritdoc IGHODirectMinter
address public immutable COLLECTOR;
// @inheritdoc IGHODirectMinter
address public immutable GHO;
// @inheritdoc IGHODirectMinter
address public immutable GHO_A_TOKEN;

modifier onlyRiskCouncilOrOwner() {
require(RISK_COUNCIL == msg.sender || owner() == msg.sender, InvalidCaller());
_;
}

constructor(IPool pool, address collector, address gho, address council) RiskCouncilControlled(council) {
constructor(IPoolAddressesProvider poolAddressesProvider, address collector, address gho) {
IPool pool = IPool(poolAddressesProvider.getPool());
POOL = pool;
POOL_CONFIGURATOR = IPoolConfigurator(poolAddressesProvider.getPoolConfigurator());
COLLECTOR = collector;
GHO = gho;
DataTypes.ReserveDataLegacy memory reserveData = pool.getReserveData(gho);
Expand All @@ -42,19 +45,25 @@ contract GHODirectMinter is Initializable, OwnableUpgradeable, IGHODirectMinter,
_disableInitializers();
}

function initialize(address owner) external virtual initializer {
function initialize(address owner, address council) external virtual initializer {
__Ownable_init(owner);
__Ownable_With_Guardian_init(council);
}

// @inheritdoc IGHODirectMinter
function mintAndSupply(uint256 amount) external onlyRiskCouncilOrOwner {
function mintAndSupply(uint256 amount) external onlyOwnerOrGuardian {
IGhoToken(GHO).mint(address(this), amount);
IERC20(GHO).forceApprove(address(POOL), amount);
DataTypes.ReserveConfigurationMap memory configuration = POOL.getConfiguration(GHO);
// setting supplycap to zero to disable it
POOL_CONFIGURATOR.setSupplyCap(GHO, 0);
POOL.supply(GHO, amount, address(this), 0);
// setting supplycap back the original value
POOL_CONFIGURATOR.setSupplyCap(GHO, configuration.getSupplyCap());
}

// @inheritdoc IGHODirectMinter
function withdrawAndBurn(uint256 amount) external onlyRiskCouncilOrOwner {
function withdrawAndBurn(uint256 amount) external onlyOwnerOrGuardian {
uint256 amountWithdrawn = POOL.withdraw(GHO, amount, address(this));
IGhoToken(GHO).burn(amountWithdrawn);
}
Expand Down
31 changes: 0 additions & 31 deletions src/RiskCouncilControlled.sol

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,21 @@
pragma solidity ^0.8.0;

import {IPool} from "aave-v3-origin/contracts/interfaces/IPool.sol";
import {IPoolConfigurator} from "aave-v3-origin/contracts/interfaces/IPoolConfigurator.sol";

interface IGHODirectMinter {
interface IGhoDirectMinter {
error InvalidAToken();

/**
* @return Returns the pool address managed by the facilitator
*/
function POOL() external view returns (IPool);

/**
* @return Returns the pool address managed by the facilitator
*/
function POOL_CONFIGURATOR() external view returns (IPoolConfigurator);

/**
* @return Returns the collector address that receives the GHO interest
*/
Expand All @@ -31,7 +37,9 @@ interface IGHODirectMinter {
* @param amount Amount of GHO to mint and supply to the pool
* @notice Due to aave rounding based on the index there might be a small rounding error, which can result in:
* - receiving slightly more aTokens
* This error is neglectable and should not have any impact on the system
* This error is neglectable and should not have any impact on the system.
* This method avoid supply cap limitations on the pool, by:
* memoizing the current supply cap -> setting it to zero(disable) -> supplying -> setting it back to the memoized value.
*/
function mintAndSupply(uint256 amount) external;

Expand All @@ -40,7 +48,7 @@ interface IGHODirectMinter {
* @param amount Amount of GHO to withdraw and burn from the pool
* @notice Due to aave rounding based on the index there might be a small rounding error, which can result in:
* - withdrawing slightly less and thus burning slightly less
* This error is neglectable and should not have any impact on the system
* This error is neglectable and should not have any impact on the system.
*/
function withdrawAndBurn(uint256 amount) external;

Expand All @@ -49,7 +57,7 @@ interface IGHODirectMinter {
* @notice Due to aave rounding based on the index there might be a small rounding error, which can result in:
* - transfering slightly more
* - transfering slightly less
* This error is neglectable and should not have any impact on the system
* This error is neglectable and should not have any impact on the system.
*/
function transferExcessToTreasury() external;
}
18 changes: 12 additions & 6 deletions src/proposals/LidoGHOListing.sol
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,11 @@ import {
ITransparentProxyFactory,
ProxyAdmin
} from "solidity-utils/contracts/transparent-proxy/interfaces/ITransparentProxyFactory.sol";
import {IAccessControl} from "openzeppelin-contracts/contracts/access/IAccessControl.sol";

import {IGhoToken} from "../interfaces/IGhoToken.sol";
import {IGhoBucketSteward} from "../interfaces/IGhoBucketSteward.sol";
import {GHODirectMinter} from "../GHODirectMinter.sol";
import {GhoDirectMinter} from "../GhoDirectMinter.sol";

/**
* @title GHO listing on Lido pool
Expand All @@ -36,17 +37,22 @@ contract LidoGHOListing is AaveV3PayloadEthereumLido {

function _postExecute() internal override {
address vaultImpl = address(
new GHODirectMinter(
AaveV3EthereumLido.POOL, address(AaveV3EthereumLido.COLLECTOR), AaveV3EthereumAssets.GHO_UNDERLYING, COUNCIL
new GhoDirectMinter(
AaveV3EthereumLido.POOL_ADDRESSES_PROVIDER,
address(AaveV3EthereumLido.COLLECTOR),
AaveV3EthereumAssets.GHO_UNDERLYING
)
);
address vault = ITransparentProxyFactory(MiscEthereum.TRANSPARENT_PROXY_FACTORY).create(
vaultImpl,
ProxyAdmin(MiscEthereum.PROXY_ADMIN),
abi.encodeWithSelector(GHODirectMinter.initialize.selector, address(this))
abi.encodeWithSelector(GhoDirectMinter.initialize.selector, address(this), COUNCIL)
);
IGhoToken(AaveV3EthereumAssets.GHO_UNDERLYING).addFacilitator(vault, "LidoGHODirectMinter", GHO_MINT_AMOUNT);
GHODirectMinter(vault).mintAndSupply(GHO_MINT_AMOUNT);
IAccessControl(address(AaveV3EthereumLido.ACL_MANAGER)).grantRole(
AaveV3EthereumLido.ACL_MANAGER.RISK_ADMIN_ROLE(), address(vault)
);
IGhoToken(AaveV3EthereumAssets.GHO_UNDERLYING).addFacilitator(vault, "LidoGhoDirectMinter", GHO_MINT_AMOUNT);
GhoDirectMinter(vault).mintAndSupply(GHO_MINT_AMOUNT);

// allow risk council to control the bucket capacity
address[] memory vaults = new address[](1);
Expand Down
Loading

4 comments on commit c7b299f

@github-actions
Copy link

Choose a reason for hiding this comment

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

🌈 Test Results
No files changed, compilation skipped

Ran 7 tests for test/Lido_GhoDirectMinter.t.sol:Lido_GHODirectMinter_Test
[PASS] test_mintAndSupply_council(uint256) (runs: 256, μ: 277656, ~: 277339)
[PASS] test_mintAndSupply_owner(uint256) (runs: 256, μ: 275381, ~: 275109)
[PASS] test_mintAndSupply_rando() (gas: 18205)
[PASS] test_transferExcessToTreasury() (gas: 864730)
Logs:
  Bound result 1000000000000000000000

[PASS] test_withdrawAndBurn_council(uint256,uint256) (runs: 256, μ: 316221, ~: 316258)
[PASS] test_withdrawAndBurn_owner(uint256,uint256) (runs: 256, μ: 312926, ~: 312918)
[PASS] test_withdrawAndBurn_rando() (gas: 18105)
Suite result: ok. 7 passed; 0 failed; 0 skipped; finished in 667.00ms (1.57s CPU time)

Ran 1 test suite in 669.86ms (667.00ms CPU time): 7 tests passed, 0 failed, 0 skipped (7 total tests)

@github-actions
Copy link

Choose a reason for hiding this comment

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

🔧 Build logs
Compiling 115 files with Solc 0.8.28
installing solc version "0.8.28"
Successfully installed solc 0.8.28
Solc 0.8.28 finished in 2.53s
Compiler run successful!
| Contract                            | Runtime Size (B) | Initcode Size (B) | Runtime Margin (B) | Initcode Margin (B) |
|-------------------------------------|------------------|-------------------|--------------------|---------------------|
| AaveV3Ethereum                      |               85 |               135 |             24,491 |              49,017 |
| AaveV3EthereumAssets                |               85 |               135 |             24,491 |              49,017 |
| AaveV3EthereumEModes                |               85 |               135 |             24,491 |              49,017 |
| AaveV3EthereumExternalLibraries     |               85 |               135 |             24,491 |              49,017 |
| AaveV3EthereumLido                  |               85 |               135 |             24,491 |              49,017 |
| AaveV3EthereumLidoAssets            |               85 |               135 |             24,491 |              49,017 |
| AaveV3EthereumLidoEModes            |               85 |               135 |             24,491 |              49,017 |
| AaveV3EthereumLidoExternalLibraries |               85 |               135 |             24,491 |              49,017 |
| Address                             |               85 |               135 |             24,491 |              49,017 |
| ChainHelpers                        |               85 |               135 |             24,491 |              49,017 |
| ChainIds                            |               85 |               135 |             24,491 |              49,017 |
| ConfiguratorInputTypes              |               85 |               135 |             24,491 |              49,017 |
| Create2Utils                        |              162 |               212 |             24,414 |              48,940 |
| Create2UtilsZkSync                  |              145 |               195 |             24,431 |              48,957 |
| DataTypes                           |               85 |               135 |             24,491 |              49,017 |
| ERC1967Proxy                        |              163 |               976 |             24,413 |              48,176 |
| ERC1967Utils                        |               85 |               135 |             24,491 |              49,017 |
| EngineFlags                         |               85 |               135 |             24,491 |              49,017 |
| Errors                              |            4,671 |             4,723 |             19,905 |              44,429 |
| GhoDirectMinter                     |            4,555 |             6,026 |             20,021 |              43,126 |
| GovV3Helpers                        |            2,384 |             2,436 |             22,192 |              46,716 |
| GovV3StorageHelpers                 |               85 |               135 |             24,491 |              49,017 |
| GovernanceV3Arbitrum                |               85 |               135 |             24,491 |              49,017 |
| GovernanceV3Avalanche               |               85 |               135 |             24,491 |              49,017 |
| GovernanceV3BNB                     |               85 |               135 |             24,491 |              49,017 |
| GovernanceV3Base                    |               85 |               135 |             24,491 |              49,017 |
| GovernanceV3Ethereum                |               85 |               135 |             24,491 |              49,017 |
| GovernanceV3Gnosis                  |               85 |               135 |             24,491 |              49,017 |
| GovernanceV3Metis                   |               85 |               135 |             24,491 |              49,017 |
| GovernanceV3Optimism                |               85 |               135 |             24,491 |              49,017 |
| GovernanceV3Polygon                 |               85 |               135 |             24,491 |              49,017 |
| GovernanceV3PolygonZkEvm            |               85 |               135 |             24,491 |              49,017 |
| GovernanceV3Scroll                  |               85 |               135 |             24,491 |              49,017 |
| GovernanceV3ZkSync                  |               85 |               135 |             24,491 |              49,017 |
| IpfsUtils                           |               85 |               135 |             24,491 |              49,017 |
| LidoGHOListing                      |           10,950 |            11,128 |             13,626 |              38,024 |
| MiscEthereum                        |               85 |               135 |             24,491 |              49,017 |
| PayloadsControllerUtils             |               85 |               135 |             24,491 |              49,017 |
| ProxyAdmin                          |            1,018 |             1,254 |             23,558 |              47,898 |
| ProxyHelpers                        |               85 |               135 |             24,491 |              49,017 |
| ReserveConfiguration                |              169 |               219 |             24,407 |              48,933 |
| SafeERC20                           |               85 |               135 |             24,491 |              49,017 |
| StorageHelpers                      |               85 |               135 |             24,491 |              49,017 |
| StorageSlot                         |               85 |               135 |             24,491 |              49,017 |
| TestNetChainIds                     |               85 |               135 |             24,491 |              49,017 |
| TransparentUpgradeableProxy         |            1,115 |             2,206 |             23,461 |              46,946 |
| WadRayMath                          |               85 |               135 |             24,491 |              49,017 |

@github-actions
Copy link

Choose a reason for hiding this comment

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

🔮 Coverage report
File Line Coverage Function Coverage Branch Coverage
src/GhoDirectMinter.sol ${\color{green}100\%}$
$22 / 22$
${\color{green}100\%}$
$5 / 5$
${\color{red}50\%}$
$1 / 2$
src/proposals/LidoGHOListing.sol ${\color{green}100\%}$
$12 / 12$
${\color{red}66.67\%}$
$2 / 3$
LidoGHOListing.newListings
${\color{green}100\%}$
$0 / 0$

@github-actions
Copy link

Choose a reason for hiding this comment

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

Gas report

TransparentUpgradeableProxy

  • size: 0 / 49152
Method min mean median max calls
mintAndSupply(uint256) 31000 222879 260802 263009 6
withdrawAndBurn(uint256) 30933 145705 158229 160364 10

Please sign in to comment.