-
Notifications
You must be signed in to change notification settings - Fork 118
Remote GSM #451
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
Closed
Closed
Remote GSM #451
Changes from 6 commits
Commits
Show all changes
24 commits
Select commit
Hold shift + click to select a range
aaeb183
feat: initial commit'
efecarranza 653f896
feat: use abstraction and extend gsm
efecarranza 21b390e
feat add natspec to remote gsm
efecarranza 9f88853
feat: add tests
efecarranza 00b5958
feat: add gho remote vault
efecarranza 0b17427
feat: make vault upgradeable and rename functioins
efecarranza 8926a08
feat: add capacity and make ownable
efecarranza 8b12183
feat: rename to GhoReserve
efecarranza e957445
feat: tests
efecarranza e2a257b
feat: more tests
efecarranza 4b2ac50
feat: 4626 edge
efecarranza af63e7f
feat: finish 4626
efecarranza bef55a1
feat: finalize tests
efecarranza bfcb5e3
feat: add more tests
efecarranza 69d162b
feat: improve natspec
efecarranza 3707b75
chore: cleanup docs
efecarranza 61923db
feat: usage position, renaming
efecarranza 1a9bb8c
chore: add period
efecarranza 4a7a101
chore: reorder events
efecarranza bb3fcf7
feat: add enumerable set
efecarranza e525002
feat: used periphery versioned init
efecarranza c35819a
chore: rename error
efecarranza 5250add
chore: test
efecarranza 479f812
feat: add error messages and tests to reserve
efecarranza 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,80 @@ | ||
| // SPDX-License-Identifier: MIT | ||
| pragma solidity ^0.8.10; | ||
|
|
||
| import {IERC20} from '@aave/core-v3/contracts/dependencies/openzeppelin/contracts/IERC20.sol'; | ||
| import {AccessControl} from '@openzeppelin/contracts/access/AccessControl.sol'; | ||
| import {VersionedInitializable} from '@aave/core-v3/contracts/protocol/libraries/aave-upgradeability/VersionedInitializable.sol'; | ||
| import {IGhoRemoteVault} from './interfaces/IGhoRemoteVault.sol'; | ||
|
|
||
| contract GhoRemoteVault is IGhoRemoteVault, AccessControl, VersionedInitializable { | ||
| /// @inheritdoc IGhoRemoteVault | ||
| bytes32 public constant FUNDS_ADMIN_ROLE = 'FUNDS_ADMIN'; | ||
|
|
||
| /// @inheritdoc IGhoRemoteVault | ||
| address public immutable GHO_TOKEN; | ||
|
|
||
| /// @dev Mapping to keep track of GHO withdrawn by an address | ||
| mapping(address => uint256) private _ghoWithdrawn; | ||
|
|
||
| /** | ||
| * @dev Throws if the caller does not have the FUNDS_ADMIN role | ||
| */ | ||
| modifier onlyFundsAdmin() { | ||
| require(_onlyFundsAdmin(), 'ONLY_FUNDS_ADMIN'); | ||
efecarranza marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| _; | ||
| } | ||
|
|
||
| /** | ||
| * @dev Constructor | ||
| * @param ghoAddress Address of GHO token on the remote chain | ||
| */ | ||
| constructor(address ghoAddress) { | ||
| require(ghoAddress != address(0), 'INVALID_ZERO_ADDRESS'); | ||
|
|
||
| GHO_TOKEN = ghoAddress; | ||
| } | ||
|
|
||
| /** | ||
| * @notice GhoRemoteVault initializer | ||
| * @param admin The address of the default admin role | ||
| */ | ||
| function initialize(address admin) external initializer { | ||
| require(admin != address(0), 'ZERO_ADDRESS_NOT_VALID'); | ||
| _grantRole(DEFAULT_ADMIN_ROLE, admin); | ||
| } | ||
|
|
||
| /// @inheritdoc IGhoRemoteVault | ||
| function withdrawGho(uint256 amount) external onlyFundsAdmin { | ||
| _ghoWithdrawn[msg.sender] += amount; | ||
| IERC20(GHO_TOKEN).transfer(msg.sender, amount); | ||
| } | ||
|
|
||
| /// @inheritdoc IGhoRemoteVault | ||
| function returnGho(uint256 amount) external onlyFundsAdmin { | ||
| _ghoWithdrawn[msg.sender] -= amount; | ||
| IERC20(GHO_TOKEN).transferFrom(msg.sender, address(this), amount); | ||
| } | ||
|
|
||
| function bridgeGho(uint256 amount) external onlyFundsAdmin { | ||
miguelmtzinf marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| // Intentionally left bank | ||
| } | ||
|
|
||
| /// @inheritdoc IGhoRemoteVault | ||
| function getWithdrawnGho(address withdrawer) external view returns (uint256) { | ||
| return _ghoWithdrawn[withdrawer]; | ||
| } | ||
|
|
||
| /// @inheritdoc IGhoRemoteVault | ||
| function GHO_REMOTE_VAULT_REVISION() public pure virtual override returns (uint256) { | ||
| return 1; | ||
| } | ||
|
|
||
| /// @inheritdoc VersionedInitializable | ||
| function getRevision() internal pure virtual override returns (uint256) { | ||
| return GHO_REMOTE_VAULT_REVISION(); | ||
| } | ||
|
|
||
| function _onlyFundsAdmin() internal view returns (bool) { | ||
| return hasRole(FUNDS_ADMIN_ROLE, msg.sender); | ||
| } | ||
| } | ||
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,79 @@ | ||
| // SPDX-License-Identifier: MIT | ||
| pragma solidity ^0.8.10; | ||
|
|
||
| import {IGhoToken} from '../../gho/interfaces/IGhoToken.sol'; | ||
| import {IRemoteGsm} from './interfaces/IRemoteGsm.sol'; | ||
| import {GhoRemoteVault} from './GhoRemoteVault.sol'; | ||
| import {Gsm} from './Gsm.sol'; | ||
|
|
||
| /** | ||
| * @title RemoteGsm | ||
| * @author Aave | ||
| * @notice Remote GHO Stability Module. It provides buy/sell facilities to go to/from an underlying asset to/from GHO. | ||
| * @dev To be covered by a proxy contract. | ||
| */ | ||
| contract RemoteGsm is IRemoteGsm, Gsm { | ||
| address internal _ghoVault; | ||
|
|
||
| /** | ||
| * @dev Constructor | ||
| * @param ghoToken The address of the GHO token contract | ||
| * @param underlyingAsset The address of the collateral asset | ||
| * @param priceStrategy The address of the price strategy | ||
| * @param ghoVault Address of the GHO vault to fund GSM trades | ||
| */ | ||
| constructor( | ||
| address ghoToken, | ||
| address underlyingAsset, | ||
| address priceStrategy, | ||
| address ghoVault | ||
| ) Gsm(ghoToken, underlyingAsset, priceStrategy) { | ||
| _updateGhoVault(ghoVault); | ||
| } | ||
|
|
||
| /// @inheritdoc IRemoteGsm | ||
| function updateGhoVault(address ghoVault) external onlyRole(CONFIGURATOR_ROLE) { | ||
| _updateGhoVault(ghoVault); | ||
| } | ||
|
|
||
| /// @inheritdoc IRemoteGsm | ||
| function getGhoVault() external view returns (address) { | ||
| return _ghoVault; | ||
| } | ||
|
|
||
| /// @inheritdoc Gsm | ||
| function _restoreGho(address originator, uint256 grossAmount) internal override { | ||
| GhoRemoteVault(_ghoVault).returnGho(grossAmount); | ||
| } | ||
|
|
||
| /// @inheritdoc Gsm | ||
| function _useGho(uint256 grossAmount) internal override { | ||
| GhoRemoteVault(_ghoVault).withdrawGho(grossAmount); | ||
| } | ||
|
|
||
| /// @inheritdoc Gsm | ||
| function _burnGhoAfterSeize(uint256 amount) internal override { | ||
| GhoRemoteVault(_ghoVault).returnGho(amount); | ||
| GhoRemoteVault(_ghoVault).bridgeGho(amount); | ||
| } | ||
|
|
||
| /// @inheritdoc Gsm | ||
| function _getUsedGho() internal view override returns (uint256) { | ||
| return GhoRemoteVault(_ghoVault).getWithdrawnGho(address(this)); | ||
| } | ||
|
|
||
| /** | ||
| * @dev Updates address of GHO Vault | ||
| * @param ghoVault The address of the GHO vault for the GSM | ||
| */ | ||
| function _updateGhoVault(address ghoVault) internal { | ||
| require(ghoVault != address(0), 'ZERO_ADDRESS_NOT_VALID'); | ||
| address oldVault = _ghoVault; | ||
| _ghoVault = ghoVault; | ||
|
|
||
| IGhoToken(GHO_TOKEN).approve(oldVault, 0); | ||
| IGhoToken(GHO_TOKEN).approve(ghoVault, type(uint256).max); | ||
|
|
||
| emit GhoVaultUpdated(oldVault, ghoVault); | ||
| } | ||
| } |
56 changes: 56 additions & 0 deletions
56
src/contracts/facilitators/gsm/interfaces/IGhoRemoteVault.sol
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,56 @@ | ||
| // SPDX-License-Identifier: MIT | ||
| pragma solidity ^0.8.0; | ||
|
|
||
| import {IAccessControl} from '@openzeppelin/contracts/access/IAccessControl.sol'; | ||
|
|
||
| interface IGhoRemoteVault is IAccessControl { | ||
| /** | ||
| * @dev Emitted when GHO tokens are withdrawn | ||
| * @param user Address withdrawing GHO | ||
| * @param amount Amount of GHO withdrawn | ||
| */ | ||
| event GhoWithdrawn(address indexed user, uint256 amount); | ||
|
|
||
| /** | ||
| * @dev Emitted when GHO tokens are returned | ||
| * @param user Address returning GHO | ||
| * @param amount Amount of GHO returned | ||
| */ | ||
| event GhoReturned(address indexed user, uint256 amount); | ||
|
|
||
| /** | ||
| * @notice Returns the identifier of the Funds Admin Role | ||
| * @return The bytes32 id hash of the Funds Admin role | ||
| */ | ||
| function FUNDS_ADMIN_ROLE() external pure returns (bytes32); | ||
|
|
||
| /** | ||
| * @notice Returns the address of the GHO token | ||
| * @return The address of GHO token contract | ||
| */ | ||
| function GHO_TOKEN() external view returns (address); | ||
|
|
||
| /** | ||
| * @notice Accepts GHO to be repaied by caller | ||
| * @param amount The amount of GHO to return | ||
| */ | ||
| function returnGho(uint256 amount) external; | ||
|
|
||
| /** | ||
| * @notice Allows allowed caller to withdraw GHO from vault | ||
| * @param amount The amount of GHO to withdraw | ||
| */ | ||
| function withdrawGho(uint256 amount) external; | ||
|
|
||
| /** | ||
| * Returns amount of GHO withdrawn by a specified address | ||
| * @param withdrawer Address of the contract that withdrew GHO from vault | ||
| */ | ||
| function getWithdrawnGho(address withdrawer) external view returns (uint256); | ||
|
|
||
| /** | ||
| * @notice Returns the GhoRemoteVault revision number | ||
| * @return The revision number | ||
| */ | ||
| function GHO_REMOTE_VAULT_REVISION() external pure returns (uint256); | ||
| } |
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: MIT | ||
| pragma solidity ^0.8.0; | ||
|
|
||
| import {IGsm} from './IGsm.sol'; | ||
|
|
||
| /** | ||
| * @title IRemoteGsm | ||
| * @author Aave | ||
| * @notice Defines the behaviour of a Remote GHO Stability Module | ||
| */ | ||
| interface IRemoteGsm is IGsm { | ||
| /** | ||
| * @dev Emitted when the GSM's vault is updated | ||
| * @param oldVault The address of the old vault | ||
| * @param newVault The address of the new vault | ||
| */ | ||
| event GhoVaultUpdated(address oldVault, address newVault); | ||
|
|
||
| /** | ||
| * Returns the address of the GHO vault | ||
| */ | ||
| function getGhoVault() external view returns (address); | ||
|
|
||
| /** | ||
| * @notice Updates the GHO vault address | ||
| * @param ghoVault The new address of the vault holding GHO | ||
| */ | ||
| function updateGhoVault(address ghoVault) external; | ||
| } |
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.