Skip to content

Commit

Permalink
add test for getExposureCap
Browse files Browse the repository at this point in the history
  • Loading branch information
parth-15 committed Jan 18, 2024
1 parent 08f2fbb commit 3cb42d6
Show file tree
Hide file tree
Showing 2 changed files with 112 additions and 0 deletions.
69 changes: 69 additions & 0 deletions src/test/TestGsm.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ contract TestGsm is TestGhoBase {
address(GHO_GSM_FIXED_PRICE_STRATEGY),
'Unexpected price strategy'
);
assertEq(gsm.getExposureCap(), 0, 'Unexpected exposure capacity');
}

function testRevertConstructorInvalidPriceStrategy() public {
Expand Down Expand Up @@ -99,6 +100,7 @@ contract TestGsm is TestGhoBase {
assertEq(assetAmount, DEFAULT_GSM_USDC_AMOUNT, 'Unexpected asset amount sold');
assertEq(USDC_TOKEN.balanceOf(ALICE), 0, 'Unexpected final USDC balance');
assertEq(GHO_TOKEN.balanceOf(ALICE), DEFAULT_GSM_GHO_AMOUNT, 'Unexpected final GHO balance');
assertEq(GHO_GSM.getExposureCap(), DEFAULT_GSM_USDC_EXPOSURE, 'Unexpected exposure capacity');
}

function testSellAsset() public {
Expand Down Expand Up @@ -130,6 +132,7 @@ contract TestGsm is TestGhoBase {
DEFAULT_GSM_USDC_AMOUNT,
'Unexpected available liquidity'
);
assertEq(GHO_GSM.getExposureCap(), DEFAULT_GSM_USDC_EXPOSURE, 'Unexpected exposure capacity');
}

function testSellAssetSendToOther() public {
Expand All @@ -152,6 +155,7 @@ contract TestGsm is TestGhoBase {
assertEq(GHO_TOKEN.balanceOf(ALICE), 0, 'Unexpected final GHO balance');
assertEq(GHO_TOKEN.balanceOf(BOB), ghoOut, 'Unexpected final GHO balance');
assertEq(GHO_TOKEN.balanceOf(address(GHO_GSM)), fee, 'Unexpected GSM GHO balance');
assertEq(GHO_GSM.getExposureCap(), DEFAULT_GSM_USDC_EXPOSURE, 'Unexpected exposure capacity');
}

function testSellAssetWithSig() public {
Expand Down Expand Up @@ -208,6 +212,7 @@ contract TestGsm is TestGhoBase {
assertEq(USDC_TOKEN.balanceOf(gsmSignerAddr), 0, 'Unexpected final USDC balance');
assertEq(GHO_TOKEN.balanceOf(gsmSignerAddr), ghoOut, 'Unexpected final GHO balance');
assertEq(GHO_TOKEN.balanceOf(address(GHO_GSM)), fee, 'Unexpected GSM GHO balance');
assertEq(GHO_GSM.getExposureCap(), DEFAULT_GSM_USDC_EXPOSURE, 'Unexpected exposure capacity');
}

function testSellAssetWithSigExactDeadline() public {
Expand Down Expand Up @@ -265,6 +270,7 @@ contract TestGsm is TestGhoBase {
assertEq(USDC_TOKEN.balanceOf(gsmSignerAddr), 0, 'Unexpected final USDC balance');
assertEq(GHO_TOKEN.balanceOf(gsmSignerAddr), ghoOut, 'Unexpected final GHO balance');
assertEq(GHO_TOKEN.balanceOf(address(GHO_GSM)), fee, 'Unexpected GSM GHO balance');
assertEq(GHO_GSM.getExposureCap(), DEFAULT_GSM_USDC_EXPOSURE, 'Unexpected exposure capacity');
}

function testRevertSellAssetWithSigExpiredSignature() public {
Expand Down Expand Up @@ -483,6 +489,7 @@ contract TestGsm is TestGhoBase {
assertEq(assetAmount, DEFAULT_GSM_USDC_AMOUNT, 'Unexpected asset amount bought');
assertEq(USDC_TOKEN.balanceOf(BOB), DEFAULT_GSM_USDC_AMOUNT, 'Unexpected final USDC balance');
assertEq(GHO_TOKEN.balanceOf(ALICE), DEFAULT_GSM_GHO_AMOUNT, 'Unexpected final GHO balance');
assertEq(GHO_GSM.getExposureCap(), DEFAULT_GSM_USDC_EXPOSURE, 'Unexpected exposure capacity');
}

function testBuyAsset() public {
Expand Down Expand Up @@ -520,6 +527,7 @@ contract TestGsm is TestGhoBase {
'Unexpected available underlying exposure'
);
assertEq(GHO_GSM.getAvailableLiquidity(), 0, 'Unexpected available liquidity');
assertEq(GHO_GSM.getExposureCap(), DEFAULT_GSM_USDC_EXPOSURE, 'Unexpected exposure capacity');
}

function testBuyAssetSendToOther() public {
Expand Down Expand Up @@ -556,6 +564,7 @@ contract TestGsm is TestGhoBase {
);
assertEq(GHO_TOKEN.balanceOf(ALICE), ghoOut, 'Unexpected final GHO balance');
assertEq(GHO_TOKEN.balanceOf(address(GHO_GSM)), sellFee + buyFee, 'Unexpected GSM GHO balance');
assertEq(GHO_GSM.getExposureCap(), DEFAULT_GSM_USDC_EXPOSURE, 'Unexpected exposure capacity');
}

function testBuyAssetWithSig() public {
Expand Down Expand Up @@ -627,6 +636,7 @@ contract TestGsm is TestGhoBase {
);
assertEq(GHO_TOKEN.balanceOf(ALICE), ghoOut, 'Unexpected final GHO balance');
assertEq(GHO_TOKEN.balanceOf(address(GHO_GSM)), sellFee + buyFee, 'Unexpected GSM GHO balance');
assertEq(GHO_GSM.getExposureCap(), DEFAULT_GSM_USDC_EXPOSURE, 'Unexpected exposure capacity');
}

function testBuyAssetWithSigExactDeadline() public {
Expand Down Expand Up @@ -699,6 +709,7 @@ contract TestGsm is TestGhoBase {
);
assertEq(GHO_TOKEN.balanceOf(ALICE), ghoOut, 'Unexpected final GHO balance');
assertEq(GHO_TOKEN.balanceOf(address(GHO_GSM)), sellFee + buyFee, 'Unexpected GSM GHO balance');
assertEq(GHO_GSM.getExposureCap(), DEFAULT_GSM_USDC_EXPOSURE, 'Unexpected exposure capacity');
}

function testBuyThenSellAtMaximumBucketCapacity() public {
Expand Down Expand Up @@ -754,6 +765,7 @@ contract TestGsm is TestGhoBase {
'Unexpected Alice GHO balance after second sell'
);
assertEq(USDC_TOKEN.balanceOf(ALICE), 0, 'Unexpected Alice USDC balance after second sell');
assertEq(GHO_GSM.getExposureCap(), DEFAULT_GSM_USDC_EXPOSURE, 'Unexpected exposure capacity');
}

function testRevertBuyAssetWithSigExpiredSignature() public {
Expand Down Expand Up @@ -1057,6 +1069,11 @@ contract TestGsm is TestGhoBase {
GHO_GSM.updateExposureCap(0);
assertEq(GHO_GSM.getExposureCap(), 0, 'Unexpected exposure capacity');

vm.expectEmit(true, true, false, true, address(GHO_GSM));
emit ExposureCapUpdated(0, 1000);
GHO_GSM.updateExposureCap(1000);
assertEq(GHO_GSM.getExposureCap(), 1000, 'Unexpected exposure capacity');

vm.stopPrank();
}

Expand Down Expand Up @@ -1271,6 +1288,7 @@ contract TestGsm is TestGhoBase {
0,
'Unexpected underlying exposure available'
);
assertEq(GHO_GSM.getExposureCap(), 0, 'Unexpected exposure capacity');
}

function testRevertSeizeWithoutAuthorization() public {
Expand Down Expand Up @@ -1487,4 +1505,55 @@ contract TestGsm is TestGhoBase {
GHO_GSM.seize();
assertEq(GHO_GSM.canSwap(), false, 'Unexpected swap state post-seize');
}

function testGetExposureCap() public {
uint256 buyFee = DEFAULT_GSM_GHO_AMOUNT.percentMul(DEFAULT_GSM_BUY_FEE);

assertEq(GHO_GSM.getExposureCap(), DEFAULT_GSM_USDC_EXPOSURE, 'Unexpected exposure capacity');

vm.prank(FAUCET);
USDC_TOKEN.mint(ALICE, 2 * DEFAULT_GSM_USDC_AMOUNT);

// Alice as configurator
GHO_GSM.grantRole(GSM_CONFIGURATOR_ROLE, ALICE);

vm.startPrank(address(ALICE));

USDC_TOKEN.approve(address(GHO_GSM), DEFAULT_GSM_USDC_AMOUNT);
GHO_GSM.sellAsset(DEFAULT_GSM_USDC_AMOUNT, ALICE);

assertEq(
GHO_GSM.getAvailableUnderlyingExposure(),
DEFAULT_GSM_USDC_EXPOSURE - DEFAULT_GSM_USDC_AMOUNT,
'Unexpected available underlying exposure'
);
assertEq(GHO_GSM.getExposureCap(), DEFAULT_GSM_USDC_EXPOSURE, 'Unexpected exposure capacity');

GHO_GSM.updateExposureCap(DEFAULT_GSM_USDC_EXPOSURE - DEFAULT_GSM_USDC_AMOUNT - 1000);
assertEq(
GHO_GSM.getExposureCap(),
DEFAULT_GSM_USDC_EXPOSURE - DEFAULT_GSM_USDC_AMOUNT - 1000,
'Unexpected exposure capacity'
);

GHO_GSM.updateExposureCap(DEFAULT_GSM_USDC_EXPOSURE);
assertEq(GHO_GSM.getExposureCap(), DEFAULT_GSM_USDC_EXPOSURE, 'Unexpected exposure capacity');
vm.stopPrank();
ghoFaucet(BOB, DEFAULT_GSM_GHO_AMOUNT + buyFee);
vm.startPrank(BOB);
GHO_TOKEN.approve(address(GHO_GSM), DEFAULT_GSM_GHO_AMOUNT + buyFee);

USDC_TOKEN.approve(address(GHO_GSM), DEFAULT_GSM_USDC_AMOUNT);
GHO_GSM.buyAsset(DEFAULT_GSM_USDC_AMOUNT, ALICE);

assertEq(GHO_GSM.getExposureCap(), DEFAULT_GSM_USDC_EXPOSURE, 'Unexpected exposure capacity');
vm.startPrank(address(ALICE));

GHO_GSM.updateExposureCap(DEFAULT_GSM_USDC_EXPOSURE - DEFAULT_GSM_USDC_AMOUNT - 1000);
assertEq(
GHO_GSM.getExposureCap(),
DEFAULT_GSM_USDC_EXPOSURE - DEFAULT_GSM_USDC_AMOUNT - 1000,
'Unexpected exposure capacity'
);
}
}
43 changes: 43 additions & 0 deletions src/test/TestGsm4626.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ contract TestGsm4626 is TestGhoBase {
vm.expectEmit(true, true, false, true);
emit ExposureCapUpdated(0, DEFAULT_GSM_USDC_EXPOSURE);
gsm.initialize(address(this), TREASURY, DEFAULT_GSM_USDC_EXPOSURE);
assertEq(gsm.getExposureCap(), DEFAULT_GSM_USDC_EXPOSURE, 'Unexpected exposure capacity');
}

function testRevertInitializeTwice() public {
Expand Down Expand Up @@ -85,6 +86,11 @@ contract TestGsm4626 is TestGhoBase {
assertEq(assetAmount, DEFAULT_GSM_USDC_AMOUNT, 'Unexpected asset amount sold');
assertEq(USDC_4626_TOKEN.balanceOf(ALICE), 0, 'Unexpected final USDC balance');
assertEq(GHO_TOKEN.balanceOf(ALICE), DEFAULT_GSM_GHO_AMOUNT, 'Unexpected final GHO balance');
assertEq(
GHO_GSM_4626.getExposureCap(),
DEFAULT_GSM_USDC_EXPOSURE,
'Unexpected exposure capacity'
);
}

function testSellAsset() public {
Expand Down Expand Up @@ -122,6 +128,11 @@ contract TestGsm4626 is TestGhoBase {
DEFAULT_GSM_USDC_AMOUNT,
'Unexpected available liquidity'
);
assertEq(
GHO_GSM_4626.getExposureCap(),
DEFAULT_GSM_USDC_EXPOSURE,
'Unexpected exposure capacity'
);
}

function testSellAssetSendToOther() public {
Expand All @@ -143,6 +154,11 @@ contract TestGsm4626 is TestGhoBase {
assertEq(GHO_TOKEN.balanceOf(ALICE), 0, 'Unexpected final GHO balance');
assertEq(GHO_TOKEN.balanceOf(BOB), ghoOut, 'Unexpected final GHO balance');
assertEq(GHO_TOKEN.balanceOf(address(GHO_GSM_4626)), fee, 'Unexpected GSM GHO balance');
assertEq(
GHO_GSM_4626.getExposureCap(),
DEFAULT_GSM_USDC_EXPOSURE,
'Unexpected exposure capacity'
);
}

function testRevertSellAssetTooMuchUnderlyingExposure() public {
Expand Down Expand Up @@ -259,6 +275,11 @@ contract TestGsm4626 is TestGhoBase {
'Unexpected final USDC balance'
);
assertEq(GHO_TOKEN.balanceOf(ALICE), DEFAULT_GSM_GHO_AMOUNT, 'Unexpected final GHO balance');
assertEq(
GHO_GSM_4626.getExposureCap(),
DEFAULT_GSM_USDC_EXPOSURE,
'Unexpected exposure capacity'
);
}

function testBuyAsset() public {
Expand Down Expand Up @@ -303,6 +324,11 @@ contract TestGsm4626 is TestGhoBase {
'Unexpected available underlying exposure'
);
assertEq(GHO_GSM_4626.getAvailableLiquidity(), 0, 'Unexpected available liquidity');
assertEq(
GHO_GSM_4626.getExposureCap(),
DEFAULT_GSM_USDC_EXPOSURE,
'Unexpected exposure capacity'
);
}

function testBuyAssetSendToOther() public {
Expand Down Expand Up @@ -345,6 +371,11 @@ contract TestGsm4626 is TestGhoBase {
sellFee + buyFee,
'Unexpected GSM GHO balance'
);
assertEq(
GHO_GSM_4626.getExposureCap(),
DEFAULT_GSM_USDC_EXPOSURE,
'Unexpected exposure capacity'
);
}

function testBuyThenSellAtMaximumBucketCapacity() public {
Expand Down Expand Up @@ -403,6 +434,11 @@ contract TestGsm4626 is TestGhoBase {
0,
'Unexpected Alice USDC balance after second sell'
);
assertEq(
GHO_GSM_4626.getExposureCap(),
DEFAULT_GSM_USDC_EXPOSURE,
'Unexpected exposure capacity'
);
}

function testRevertBuyAssetZeroAmount() public {
Expand Down Expand Up @@ -639,6 +675,12 @@ contract TestGsm4626 is TestGhoBase {
vm.expectEmit(true, true, false, true, address(GHO_GSM_4626));
emit ExposureCapUpdated(DEFAULT_GSM_USDC_EXPOSURE, 0);
GHO_GSM_4626.updateExposureCap(0);
assertEq(GHO_GSM_4626.getExposureCap(), 0, 'Unexpected exposure capacity');

vm.expectEmit(true, true, false, true, address(GHO_GSM_4626));
emit ExposureCapUpdated(0, 1000);
GHO_GSM_4626.updateExposureCap(1000);
assertEq(GHO_GSM_4626.getExposureCap(), 1000, 'Unexpected exposure capacity');

vm.stopPrank();
}
Expand Down Expand Up @@ -836,6 +878,7 @@ contract TestGsm4626 is TestGhoBase {
DEFAULT_GSM_USDC_AMOUNT,
'Unexpected USDC after token balance'
);
assertEq(GHO_GSM_4626.getExposureCap(), 0, 'Unexpected exposure capacity');
}

function testRevertSeizeWithoutAuthorization() public {
Expand Down

0 comments on commit 3cb42d6

Please sign in to comment.