-
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 18 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,99 @@ | ||
| // SPDX-License-Identifier: MIT | ||
| pragma solidity ^0.8.10; | ||
|
|
||
| import {IERC20} from '@aave/core-v3/contracts/dependencies/openzeppelin/contracts/IERC20.sol'; | ||
| import {Ownable} from '@openzeppelin/contracts/access/Ownable.sol'; | ||
| import {VersionedInitializable} from '@aave/core-v3/contracts/protocol/libraries/aave-upgradeability/VersionedInitializable.sol'; | ||
| import {IGhoReserve} from './interfaces/IGhoReserve.sol'; | ||
|
|
||
| /** | ||
| * @title GhoReserve | ||
| * @author Aave/TokenLogic | ||
| * @notice It allows approved entities to withdraw and return GHO funds, with a defined maximum withdrawal capacity per entity. | ||
| * @dev To be covered by a proxy contract. | ||
| */ | ||
| contract GhoReserve is Ownable, VersionedInitializable, IGhoReserve { | ||
| /// @inheritdoc IGhoReserve | ||
| address public immutable GHO_TOKEN; | ||
|
|
||
| /// Map of entities and their assigned capacity and amount of GHO used | ||
| mapping(address => GhoUsage) private _ghoUsage; | ||
|
|
||
| /** | ||
| * @dev Constructor | ||
| * @param initialOwner The address of the owner | ||
| * @param ghoAddress The address of the GHO token on the remote chain | ||
| */ | ||
| constructor(address initialOwner, address ghoAddress) Ownable() { | ||
| require(initialOwner != address(0), 'ZERO_ADDRESS_NOT_VALID'); | ||
| require(ghoAddress != address(0), 'ZERO_ADDRESS_NOT_VALID'); | ||
|
|
||
| _transferOwnership(initialOwner); | ||
|
||
| GHO_TOKEN = ghoAddress; | ||
| } | ||
|
|
||
| /** | ||
| * @dev Initializer | ||
| * @param newOwner The address of the new owner | ||
| */ | ||
| function initialize(address newOwner) external initializer { | ||
| require(newOwner != address(0), 'ZERO_ADDRESS_NOT_VALID'); | ||
| _transferOwnership(newOwner); | ||
| } | ||
|
|
||
| /// @inheritdoc IGhoReserve | ||
| function use(uint256 amount) external { | ||
| GhoUsage storage entity = _ghoUsage[msg.sender]; | ||
| require(entity.limit >= entity.used + amount, 'LIMIT_REACHED'); | ||
miguelmtzinf marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
|
|
||
| entity.used += uint128(amount); | ||
| IERC20(GHO_TOKEN).transfer(msg.sender, amount); | ||
| emit GhoUsed(msg.sender, amount); | ||
| } | ||
|
|
||
| /// @inheritdoc IGhoReserve | ||
| function restore(uint256 amount) external { | ||
| _ghoUsage[msg.sender].used -= uint128(amount); | ||
| IERC20(GHO_TOKEN).transferFrom(msg.sender, address(this), amount); | ||
| emit GhoRestored(msg.sender, amount); | ||
| } | ||
|
|
||
| /// @inheritdoc IGhoReserve | ||
| function transfer(address to, uint256 amount) external onlyOwner { | ||
| IERC20(GHO_TOKEN).transfer(to, amount); | ||
| emit GhoTransferred(to, amount); | ||
| } | ||
|
|
||
| /// @inheritdoc IGhoReserve | ||
| function setLimit(address entity, uint256 limit) external onlyOwner { | ||
| _ghoUsage[entity].limit = uint128(limit); | ||
|
|
||
| emit GhoLimitUpdated(entity, limit); | ||
| } | ||
|
|
||
| /// @inheritdoc IGhoReserve | ||
| function getUsed(address entity) external view returns (uint256) { | ||
| return _ghoUsage[entity].used; | ||
| } | ||
|
|
||
| /// @inheritdoc IGhoReserve | ||
| function getUsage(address entity) external view returns (uint256, uint256) { | ||
| GhoUsage memory usage = _ghoUsage[entity]; | ||
| return (usage.limit, usage.used); | ||
| } | ||
|
|
||
| /// @inheritdoc IGhoReserve | ||
| function getLimit(address entity) external view returns (uint256) { | ||
| return _ghoUsage[entity].limit; | ||
| } | ||
|
|
||
efecarranza marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| /// @inheritdoc IGhoReserve | ||
| function GHO_REMOTE_RESERVE_REVISION() public pure virtual override returns (uint256) { | ||
| return 1; | ||
| } | ||
|
|
||
| /// @inheritdoc VersionedInitializable | ||
| function getRevision() internal pure virtual override returns (uint256) { | ||
| return GHO_REMOTE_RESERVE_REVISION(); | ||
| } | ||
| } | ||
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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wondering if we should add global variables for total limit and total used. It's a bit hard to iterate over entities also, to calculate totals
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would total limit be every time we set a limit +/- to the global variable? For used it's easy to keep track
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yeah, would be keeping global accounting every time an entity updates its usage (limit or used). Not sure it's completely needed