Skip to content
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

[SC-231] Build basic sparklend cap automator #1

Merged
merged 63 commits into from
Dec 15, 2023
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
10ccb6f
docs: create basic readme
barrutko Nov 17, 2023
e908dc6
chore: remove template contracts
barrutko Nov 17, 2023
e2e383e
feat: implement admin functions
barrutko Nov 21, 2023
b7abc9e
reofactor: separate borrow and supply configs
barrutko Nov 22, 2023
ed216d0
feat: implement cap updates
barrutko Nov 27, 2023
bf2f6ed
refactor: extract _calculateNewCap
barrutko Nov 27, 2023
9356226
test: setup remaining tests structure
barrutko Nov 27, 2023
7e9d791
refactor: add minor refactoring
barrutko Nov 27, 2023
290638f
test: enhance mock data provider
barrutko Nov 27, 2023
dbe3cfe
test: add more tests
barrutko Nov 27, 2023
c86de1e
test: add more tests
barrutko Nov 28, 2023
506d4b3
refactor: reorder functions; add interface
barrutko Nov 28, 2023
d57a442
docs: add descriptions
barrutko Nov 28, 2023
113f849
feat: add events to the interface
barrutko Nov 28, 2023
60a02ed
feat: add event emissions
barrutko Nov 28, 2023
07aab47
test: add events tests
barrutko Nov 28, 2023
f488d1b
refactor: align
barrutko Nov 28, 2023
112973e
refactor: improve naming
barrutko Nov 30, 2023
031f4cd
refactor: use type(uint48).max
barrutko Nov 30, 2023
78cb436
forge install: openzeppelin-contracts
barrutko Dec 1, 2023
81db2d1
refactor: use OZ Ownable
barrutko Dec 1, 2023
a585596
refactor: remove authority
barrutko Dec 1, 2023
dde4f82
forge install: openzeppelin-contracts
barrutko Dec 5, 2023
eb14a91
forge install: aave-v3-core
barrutko Dec 5, 2023
4a62fb8
refactor: refactor data provider calls
barrutko Dec 5, 2023
80619d3
feat: use low level pool calls
barrutko Dec 5, 2023
775013c
chore: fix modules
barrutko Dec 5, 2023
ad6de28
chore: fix modules
barrutko Dec 5, 2023
c318356
feat: add proper decimals handling
barrutko Dec 6, 2023
b796815
refactor: use preexisting interfaces
barrutko Dec 6, 2023
8dc3dea
refactor: pack max and gap in smaller variables
barrutko Dec 6, 2023
0316970
refactor: type pool and poolConfigurator
barrutko Dec 6, 2023
16614a0
feat: use PoolAddressesProvider
barrutko Dec 6, 2023
a38e0dd
refactor: add more refactorings
barrutko Dec 6, 2023
78a0da8
refactor: refactor _calculateNewCap
barrutko Dec 6, 2023
c112c36
feat: add accruedToTreasury to calculations
barrutko Dec 6, 2023
733e906
test: add accruedToTreasury component test
barrutko Dec 7, 2023
fd8ce26
refactor: add more refactorings
barrutko Dec 7, 2023
85cabb1
fix: fix if spacing
barrutko Dec 7, 2023
1357183
fix: fix typo
barrutko Dec 7, 2023
78ab46a
feat: validate against aave constants
barrutko Dec 7, 2023
8050f0c
fix: use scaledTotalSupply
barrutko Dec 7, 2023
ddeaa37
refactor: add minor refactorings
barrutko Dec 7, 2023
f673a21
refactor: refactor MockPool
barrutko Dec 7, 2023
24da86d
test: improve cooldown test
barrutko Dec 7, 2023
24dfde8
fix: change ' to "
barrutko Dec 8, 2023
f8da773
docs: add a comment
barrutko Dec 8, 2023
14998b3
fix: reorder the formula
barrutko Dec 8, 2023
a894614
fix: fix the formula
barrutko Dec 8, 2023
3f268e9
refactor: implement more changes
barrutko Dec 8, 2023
4ff2404
refactor: apply more changes
barrutko Dec 8, 2023
3d3704a
feat: add execSupply and execBorrow
barrutko Dec 8, 2023
73eb021
refactor: add more minor changes
barrutko Dec 8, 2023
4d71c78
fix: add spaces
barrutko Dec 11, 2023
af95999
refactor: add MockPoolConfigurator
barrutko Dec 11, 2023
502dfc8
refactor: add minor refactorings
barrutko Dec 11, 2023
74d591f
refactor: implement review changes
barrutko Dec 12, 2023
384eaa9
refactor: remove redundant safe casts
barrutko Dec 12, 2023
f230689
fix: fix assertions
barrutko Dec 12, 2023
bf2587c
refactor: remove unnecessary local variable
barrutko Dec 12, 2023
f8cf2a8
refactor: implement review comments
barrutko Dec 13, 2023
839fcd3
test: enhance tests for boundary conditions
barrutko Dec 13, 2023
7220e48
refactor: apply minor changes
barrutko Dec 14, 2023
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
18 changes: 13 additions & 5 deletions src/CapAutomator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ contract CapAutomator is ICapAutomator, Ownable {
uint256 max,
uint256 gap,
uint256 increaseCooldown
) external onlyOwner {
) external override onlyOwner {
require(max > 0, "CapAutomator/invalid-cap");
require(max <= ReserveConfiguration.MAX_VALID_SUPPLY_CAP, "CapAutomator/invalid-cap");
lucas-manuel marked this conversation as resolved.
Show resolved Hide resolved
require(gap <= max, "CapAutomator/invalid-gap");
Expand All @@ -78,7 +78,7 @@ contract CapAutomator is ICapAutomator, Ownable {
uint256 max,
uint256 gap,
uint256 increaseCooldown
) external onlyOwner {
) external override onlyOwner {
require(max > 0, "CapAutomator/invalid-cap");
require(max <= ReserveConfiguration.MAX_VALID_BORROW_CAP, "CapAutomator/invalid-cap");
require(gap <= max, "CapAutomator/invalid-gap");
Expand All @@ -100,13 +100,13 @@ contract CapAutomator is ICapAutomator, Ownable {
);
}

function removeSupplyCapConfig(address asset) external onlyOwner {
function removeSupplyCapConfig(address asset) external override onlyOwner {
delete supplyCapConfigs[asset];

emit RemoveSupplyCapConfig(asset);
}

function removeBorrowCapConfig(address asset) external onlyOwner {
function removeBorrowCapConfig(address asset) external override onlyOwner {
delete borrowCapConfigs[asset];

emit RemoveBorrowCapConfig(asset);
Expand All @@ -116,11 +116,19 @@ contract CapAutomator is ICapAutomator, Ownable {
/*** Public Functions ***/
/**********************************************************************************************/

function exec(address asset) external returns (uint256 newSupplyCap, uint256 newBorrowCap){
function exec(address asset) external override returns (uint256 newSupplyCap, uint256 newBorrowCap) {
newSupplyCap = _updateSupplyCapConfig(asset);
newBorrowCap = _updateBorrowCapConfig(asset);
}

function execSupply(address asset) external override returns (uint256) {
return _updateSupplyCapConfig(asset);
}

function execBorrow(address asset) external override returns (uint256) {
return _updateBorrowCapConfig(asset);
}
lucas-manuel marked this conversation as resolved.
Show resolved Hide resolved

/**********************************************************************************************/
/*** Internal Functions ***/
/**********************************************************************************************/
Expand Down
28 changes: 25 additions & 3 deletions src/interfaces/ICapAutomator.sol
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ interface ICapAutomator {

/**
* @dev Event to log the removing of a borrow cap config.
* @param asset The address of the asset for which supply borrow was removed
* @param asset The address of the asset for which borrow config was removed
*/
event RemoveBorrowCapConfig(address indexed asset);

Expand Down Expand Up @@ -155,14 +155,36 @@ interface ICapAutomator {
/**********************************************************************************************/

/**
* @dev A public function that updates supply and borrow caps on markets of a given asset.
* @dev A public function that updates supply and borrow caps on market of a given asset.
* @dev The supply and borrow caps are going to be set to, respectively, the values equal
* @dev to the sum of current supply and the supply cap gap and the the sum of current borrows and the borrow cap gap.
* @dev to the sum of current supply and the supply cap gap and the sum of current borrows and the borrow cap gap.
* @dev The caps are only going to be increased if the required cooldown time has passed.
* @dev Calling this function more than once per block will not have any additional effect.
* @param asset The address of the asset which caps are going to be updated
* @return newSupplyCap A newly set supply cap, or the old one if it was not updated
* @return newBorrowCap A newly set borrow cap, or the old one if it was not updated
*/
function exec(address asset) external returns (uint256 newSupplyCap, uint256 newBorrowCap);

/**
* @dev A public function that updates supply cap on market of a given asset.
* @dev The supply cap is going to be set to the value equal
* @dev to the sum of current supply and the supply cap gap.
* @dev The cap is only going to be increased if the required cooldown time has passed.
* @dev Calling this function more than once per block will not have any additional effect.
* @param asset The address of the asset which cap is going to be updated
* @return newSupplyCap A newly set supply cap, or the old one if it was not updated
*/
function execSupply(address asset) external returns (uint256 newSupplyCap);

/**
* @dev A public function that updates borrow cap on market of a given asset.
* @dev The borrow cap is going to be set to the values equal
* @dev to the sum of current borrows and the borrow cap gap.
* @dev The caps is only going to be increased if the required cooldown time has passed.
* @dev Calling this function more than once per block will not have any additional effect.
* @param asset The address of the asset which cap is going to be updated
* @return newBorrowCap A newly set borrow cap, or the old one if it was not updated
*/
function execBorrow(address asset) external returns (uint256 newBorrowCap);
}
Loading
Loading