Skip to content

Commit

Permalink
Merge pull request #14 from DODOEX/fix-first-deposit
Browse files Browse the repository at this point in the history
fix first deposit
  • Loading branch information
Attens1423 authored Jan 12, 2024
2 parents 7baaa70 + 5a11a3f commit 6e25d30
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 18 deletions.
4 changes: 4 additions & 0 deletions contracts/GasSavingPool/impl/GSPFunding.sol
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,10 @@ contract GSPFunding is GSPVault {
// The target will be updated
_BASE_TARGET_ = uint112(shares);
_QUOTE_TARGET_ = uint112(DecimalMath.mulFloor(shares, _I_));
// Lock 1001 shares permanently in first deposit
require(shares > 2001, "MINT_AMOUNT_NOT_ENOUGH");
_mint(address(0), 1001);
shares -= 1001;
} else if (baseReserve > 0 && quoteReserve > 0) {
// case 2. normal case
uint256 baseInputRatio = DecimalMath.divFloor(baseInput, baseReserve);
Expand Down
42 changes: 24 additions & 18 deletions test/TestGasSavingPool.t.sol
Original file line number Diff line number Diff line change
Expand Up @@ -74,37 +74,43 @@ contract TestGasSavingPool is Test {
(shares2, baseInput2, quoteInput2) = dsp.buyShares(USER);
gsp.getPMMState();
dsp.getPMMState();
assertEq(shares1, shares2, "gsp shares != dsp shares");
assertEq(shares1, 1e19);
if (i == 0) {
assertEq(shares1 + 1001, shares2, "gsp shares != dsp shares");
assertEq(shares1 + 1001, 1e19);
assertEq(shares2, 1e19);
} else {
assertEq(shares1, 1e19);
assertEq(shares2, 1e19);
}
assertEq(baseInput1, baseInput2, "gsp baseInput != dsp baseInput");
assertEq(baseInput1, 1e19);
assertEq(quoteInput1, quoteInput2, "gsp quoteInput != dsp quoteInput");
assertEq(quoteInput1, 1e7);
assertEq(gsp.balanceOf(USER), dsp.balanceOf(USER), "gsp total shares != dsp total shares");
uint256 totShare = i == 0 ? 1e19 : 2 * 1e19;
assertEq(gsp.balanceOf(USER) + 1001, dsp.balanceOf(USER), "gsp total shares != dsp total shares");
uint256 totShare = i == 0 ? 1e19 - 1001 : 2 * 1e19 - 1001;
assertEq(gsp.balanceOf(USER), totShare);
}
// sell shares
(uint256 baseAmount1, uint256 quoteAmount1) = gsp.sellShares(gsp.balanceOf(USER) / 2, USER, 0, 0, "", block.timestamp);
(uint256 baseAmount2, uint256 quoteAmount2) = dsp.sellShares(dsp.balanceOf(USER) / 2, USER, 0, 0, "", block.timestamp);
(uint256 baseAmount1, uint256 quoteAmount1) = gsp.sellShares(1e19, USER, 0, 0, "", block.timestamp);
(uint256 baseAmount2, uint256 quoteAmount2) = dsp.sellShares(1e19, USER, 0, 0, "", block.timestamp);
gsp.getPMMState();
dsp.getPMMState();
assertEq(baseAmount1, baseAmount2, "gsp baseAmount != dsp baseAmount");
assertEq(baseAmount1, 1e19);
assertEq(quoteAmount1, quoteAmount2, "gsp quoteAmount != dsp quoteAmount");
assertEq(quoteAmount1, 1e7);
assertEq(gsp.balanceOf(USER), dsp.balanceOf(USER), "gsp total shares != dsp total shares");
assertEq(gsp.balanceOf(USER), 1e19);
assertEq(gsp.balanceOf(USER) + 1001, dsp.balanceOf(USER), "gsp total shares != dsp total shares");
assertEq(gsp.balanceOf(USER), 1e19 - 1001);
// sell shares
(baseAmount1, quoteAmount1) = gsp.sellShares(gsp.balanceOf(USER), USER, 0, 0, "", block.timestamp);
(baseAmount2, quoteAmount2) = dsp.sellShares(dsp.balanceOf(USER), USER, 0, 0, "", block.timestamp);
(baseAmount1, quoteAmount1) = gsp.sellShares(1e19 - 1001, USER, 0, 0, "", block.timestamp);
(baseAmount2, quoteAmount2) = dsp.sellShares(1e19 - 1001, USER, 0, 0, "", block.timestamp);
gsp.getPMMState();
dsp.getPMMState();
assertEq(baseAmount1, baseAmount2, "gsp baseAmount != dsp baseAmount");
assertEq(baseAmount1, 1e19);
assertEq(baseAmount1, 9999999999999998999);
assertEq(quoteAmount1, quoteAmount2, "gsp quoteAmount != dsp quoteAmount");
assertEq(quoteAmount1, 1e7);
assertEq(gsp.balanceOf(USER), dsp.balanceOf(USER), "gsp total shares != dsp total shares");
assertEq(quoteAmount1, 9999999);
assertEq(gsp.balanceOf(USER) + 1001, dsp.balanceOf(USER), "gsp total shares != dsp total shares");
assertEq(gsp.balanceOf(USER), 0);
}

Expand All @@ -126,7 +132,7 @@ contract TestGasSavingPool is Test {
dai.transfer(address(dsp), BASE_RESERVE);
usdc.transfer(address(dsp), QUOTE_RESERVE);
(uint256 shares2, uint256 baseInput2, uint256 quoteInput2) = dsp.buyShares(USER);
assertEq(shares1, shares2, "gsp shares != dsp shares");
assertEq(shares1 + 1001, shares2, "gsp shares != dsp shares");
assertEq(baseInput1, baseInput2, "gsp baseInput != dsp baseInput");
assertEq(quoteInput1, quoteInput2, "gsp quoteInput != dsp quoteInput");

Expand Down Expand Up @@ -189,7 +195,7 @@ contract TestGasSavingPool is Test {
dai.transfer(address(dsp), BASE_RESERVE);
usdc.transfer(address(dsp), QUOTE_RESERVE);
(uint256 shares2, uint256 baseInput2, uint256 quoteInput2) = dsp.buyShares(USER);
assertEq(shares1, shares2, "gsp shares != dsp shares");
assertEq(shares1 + 1001, shares2, "gsp shares != dsp shares");
assertEq(baseInput1, baseInput2, "gsp baseInput != dsp baseInput");
assertEq(quoteInput1, quoteInput2, "gsp quoteInput != dsp quoteInput");

Expand Down Expand Up @@ -256,7 +262,7 @@ contract TestGasSavingPool is Test {
usdc.transfer(address(dsp), QUOTE_RESERVE);
(uint256 shares2, uint256 baseInput2, uint256 quoteInput2) = dsp.buyShares(USER);
vm.stopPrank();
assertEq(shares1, shares2, "gsp shares != dsp shares");
assertEq(shares1 + 1001, shares2, "gsp shares != dsp shares");
assertEq(baseInput1, baseInput2, "gsp baseInput != dsp baseInput");
assertEq(quoteInput1, quoteInput2, "gsp quoteInput != dsp quoteInput");

Expand Down Expand Up @@ -284,7 +290,7 @@ contract TestGasSavingPool is Test {
// burn shares
vm.startPrank(USER);
(uint256 baseAmount1, uint256 quoteAmount1) = gsp.sellShares(gsp.balanceOf(USER), USER, 0, 0, "", block.timestamp);
(uint256 baseAmount2, uint256 quoteAmount2) = dsp.sellShares(dsp.balanceOf(USER), USER, 0, 0, "", block.timestamp);
(uint256 baseAmount2, uint256 quoteAmount2) = dsp.sellShares(dsp.balanceOf(USER) - 1001, USER, 0, 0, "", block.timestamp);
vm.stopPrank();
assertEq(baseAmount1, baseAmount2, "gsp baseAmount != dsp baseAmount");
assertEq(quoteAmount1, quoteAmount2, "gsp quoteAmount != dsp quoteAmount");
Expand All @@ -307,7 +313,7 @@ contract TestGasSavingPool is Test {
dai.transfer(address(dsp), BASE_RESERVE);
usdc.transfer(address(dsp), QUOTE_RESERVE);
(uint256 shares2, uint256 baseInput2, uint256 quoteInput2) = dsp.buyShares(USER);
assertEq(shares1, shares2, "gsp shares != dsp shares");
assertEq(shares1 + 1001, shares2, "gsp shares != dsp shares");
assertEq(baseInput1, baseInput2, "gsp baseInput != dsp baseInput");
assertEq(quoteInput1, quoteInput2, "gsp quoteInput != dsp quoteInput");

Expand Down

0 comments on commit 6e25d30

Please sign in to comment.