Skip to content

Commit

Permalink
update gsp and delete adjustI
Browse files Browse the repository at this point in the history
  • Loading branch information
Skyewwww authored and Attens1423 committed Jul 23, 2024
1 parent e91109d commit ede98f0
Show file tree
Hide file tree
Showing 3 changed files with 2 additions and 51 deletions.
1 change: 1 addition & 0 deletions contracts/GasSavingPool/impl/GSP.sol
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,7 @@ contract GSP is GSPTrader, GSPFunding {
function changeOracle(address newOracle) public onlyAdmin {
require(newOracle != address(0), "INVALID_ORACLE");
_O_ = newOracle;
_I_ = IOracle(_O_).prices(address(_BASE_TOKEN_));
emit ChangeOracle(newOracle);
}

Expand Down
24 changes: 0 additions & 24 deletions contracts/GasSavingPool/impl/GSPVault.sol
Original file line number Diff line number Diff line change
Expand Up @@ -139,30 +139,6 @@ contract GSPVault is GSPStorage {
}
}

/**
* @notice PriceLimit is used for oracle change protection
* @notice It sets a ratio where the relative deviation between the new price and the old price cannot exceed this ratio.
* @dev The default priceLimit is 1e3, the decimals of priceLimit is 1e6
* @param priceLimit The new price limit
*/
function adjustPriceLimit(uint256 priceLimit) external onlyAdmin {
// the default priceLimit is 1e3
require(priceLimit <= 1e6, "INVALID_PRICE_LIMIT");
_PRICE_LIMIT_ = priceLimit;
}

/**
* @notice Adjust oricle price i, only for admin
*/
function adjustPrice(uint256 i) external onlyAdmin {
// the difference between i and _I_ should be less than priceLimit
uint256 offset = i > _I_ ? i - _I_ : _I_ - i;
require((offset * 1e6 / _I_) <= _PRICE_LIMIT_, "EXCEED_PRICE_LIMIT");
_I_ = i;

emit IChange(i);
}

/**
* @notice Adjust mtFee rate, only for maintainer
* @dev The decimals of mtFee rate is 1e18
Expand Down
28 changes: 1 addition & 27 deletions test/GSPVault.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -67,20 +67,7 @@ contract TestGSPVault is Test {
}

function testOnlyMaintainerCanAdjustParams() public {
vm.startPrank(ADMIN);
// adjust price limit
gsp.adjustPriceLimit(1e4);
assertEq(gsp._PRICE_LIMIT_(), 1e4);

// adjust price
uint256 priceBefore = gsp._I_();
assertTrue(priceBefore == I);
gsp.adjustPrice((1e6 + 1e4));
uint256 priceAfter = gsp._I_();
assertTrue(priceAfter == (1e6 + 1e4));
vm.stopPrank();

// adjust mtfee rate
// adjust mtfee rate
uint256 mtFeeRateBefore = gsp._MT_FEE_RATE_();
assertTrue(mtFeeRateBefore == MT_FEE_RATE);
vm.prank(MAINTAINER);
Expand Down Expand Up @@ -286,19 +273,6 @@ contract TestGSPVault is Test {
gsp.permit(USER, OTHER, value, deadline, v, r, s);
}


function testAdjustPriceLimitIsInvalid() public{
vm.startPrank(ADMIN);
vm.expectRevert("INVALID_PRICE_LIMIT");
gsp.adjustPriceLimit(1e7);
}

function testAdjustPriceExceedPriceLimit() public{
vm.startPrank(ADMIN);
vm.expectRevert("EXCEED_PRICE_LIMIT");
gsp.adjustPrice((2e6));
}

function testAdjustMtFeeRateIsInvalid() public{
vm.startPrank(MAINTAINER);
vm.expectRevert("INVALID_MT_FEE_RATE");
Expand Down

0 comments on commit ede98f0

Please sign in to comment.