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

fix l8 #223

Merged
merged 1 commit into from
Dec 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 2 additions & 2 deletions src/services/debit/GmxService.sol
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ contract GmxService is AuctionRateModel, DebitService {

function quote(Agreement memory agreement) public view override returns (uint256[] memory) {
uint256[] memory results = new uint256[](1);
uint256 aumInUsdg = glpManager.getAumInUsdg(false);
uint256 aumInUsdg = glpManager.getAumInUsdg(true);
uint256 glpSupply = glp.totalSupply();

if (glpSupply == 0) revert ZeroGlpSupply();
Expand All @@ -146,7 +146,7 @@ contract GmxService is AuctionRateModel, DebitService {

uint256 feeBasisPoints = usdgVault.getFeeBasisPoints(
agreement.loans[0].token,
usdgDelta,
usdgAmount,
usdgVault.swapFeeBasisPoints(),
usdgVault.taxBasisPoints(),
false
Expand Down
15 changes: 9 additions & 6 deletions test/services/AaveService.general.test.sol
Original file line number Diff line number Diff line change
Expand Up @@ -132,14 +132,15 @@ contract AaveGeneralTest is Test, IERC721Receiver {
return order;
}

function _openOrder(uint256 vaultAmount, uint256 loan, uint256 margin, uint64 warp) internal {
function _openOrder(uint256 vaultAmount, uint256 loan, uint256 margin, uint64 warp) internal returns (bool) {
warp = warp % (365 * 86400); // Warp 1y maximum
(loan, margin) = _prepareVaultAndUser(vaultAmount, loan, margin);
IService.Order memory order = _prepareOrder(loan, margin);
// No need to check invariants: they are already checked in other tests
if (order.agreement.loans[0].margin < 1e6) return;
if (order.agreement.loans[0].margin < 1e6) return false;
service.open(order);
vm.warp(block.timestamp + warp);
return true;
}

function _getInterestAndSpread(uint256 tokenID) internal returns (uint256, uint256) {
Expand Down Expand Up @@ -248,14 +249,16 @@ contract AaveGeneralTest is Test, IERC721Receiver {
}

function testInterestRateChange(uint256 vaultAmount, uint256 loan, uint256 margin, uint64 warp) public {
_openOrder(vaultAmount, loan, margin, warp);
(uint256 interest1, ) = _getInterestAndSpread(0);
uint256 interest1;
uint256 interest2;
bool opened = _openOrder(vaultAmount, loan, margin, warp);
if (opened) (interest1, ) = _getInterestAndSpread(0);
// Open a new order: time is already warped by "warp" after first one
_openOrder(vaultAmount, loan, margin, 0);
opened = _openOrder(vaultAmount, loan, margin, 0);
// there is a chance that latest order was not open due to margin constraint
// I add this check to avoid index out of bounds
if (service.id() > 1) {
(uint256 interest2, ) = _getInterestAndSpread(1);
if (opened) (interest2, ) = _getInterestAndSpread(1);
uint256 rateDecay = warp < 2 * service.halvingTime(loanTokens[0])
? (interest1 * (2 * service.halvingTime(loanTokens[0]) - warp)) /
(2 * service.halvingTime(loanTokens[0]))
Expand Down
12 changes: 4 additions & 8 deletions test/services/GmxService.test.sol
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,8 @@ contract GmxServiceTest is BaseIntegrationServiceTest {
}

function _equalityWithTolerance(uint256 amount1, uint256 amount2, uint256 tolerance) internal {
assertGe(amount1 + tolerance, amount2);
assertGe(amount2 + tolerance, amount1);
assertGe(amount1 + tolerance, amount2, "amount1 + tolerance >= amount2 failed");
assertGe(amount2 + tolerance, amount1, "amount2 + tolerance >= amount1 failed");
}

function setUp() public override {
Expand Down Expand Up @@ -185,13 +185,9 @@ contract GmxServiceTest is BaseIntegrationServiceTest {
.getAgreement(0);

IService.Agreement memory agreement = IService.Agreement(loan, collaterals, createdAt, IService.Status.OPEN);

uint256 quoted = service.quote(agreement)[0];
service.close(0, abi.encode(uint256(1)));
_equalityWithTolerance(
usdc.balanceOf(address(this)),
initial + service.quote(agreement)[0] - loan[0].amount,
1
);
_equalityWithTolerance(usdc.balanceOf(address(this)), initial + quoted - loan[0].amount, 1);
}

// setting to private since it becomes too heavy
Expand Down
Loading