-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
a2f7087
commit 17a5a48
Showing
3 changed files
with
115 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
//SPDX-License-Identifier: MIT | ||
pragma solidity ~0.8.17; | ||
|
||
import {Test} from "forge-std/Test.sol"; | ||
import {LaunchAuctionPriceOracleBase} from "./LaunchAuctionPriceOracleBase.t.sol"; | ||
import {FixedPointMathLib} from "solady/utils/FixedPointMathLib.sol"; | ||
|
||
contract DecayedPremium is LaunchAuctionPriceOracleBase { | ||
function test_decayedPremium_zeroElapsed() public view { | ||
uint256 elapsed = 0; | ||
uint256 expectedPremium = startPremium; | ||
uint256 actualPremium = oracle.decayedPremium(elapsed); | ||
assertEq(actualPremium, expectedPremium); | ||
} | ||
|
||
function test_decayedPremium_boundaryConditions() public view { | ||
uint256 zeroElapsedPremium = oracle.decayedPremium(0); | ||
assertEq(zeroElapsedPremium, startPremium); | ||
|
||
uint256 auctionEndPremium = oracle.decayedPremium(totalDays * 1 days); | ||
assertTrue(auctionEndPremium < oracle.endValue()); | ||
} | ||
|
||
function test_decayedPremium_halfPeriod() public view { | ||
uint256 elapsed = 1 hours / 2; | ||
uint256 expectedPremium = 70710678118654752400; // Calculated expected value for premium price after 1/2 day | ||
uint256 actualPremium = oracle.decayedPremium(elapsed); | ||
assertEq(actualPremium, expectedPremium); | ||
} | ||
|
||
function test_decayedPremium_threePeriods() public view { | ||
uint256 elapsed = 3 hours; | ||
uint256 expectedPremium = 12499999999999999900; // Calculated expected value for premium price after 3 days | ||
uint256 actualPremium = oracle.decayedPremium(elapsed); | ||
assertEq(actualPremium, expectedPremium); | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
test/LaunchAuctionPriceOracle/ExponentialPremiumFuzzTest.t.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
//SPDX-License-Identifier: MIT | ||
pragma solidity ~0.8.17; | ||
|
||
import {Test, console} from "forge-std/Test.sol"; | ||
import {LaunchAuctionPriceOracleBase} from "./LaunchAuctionPriceOracleBase.t.sol"; | ||
import {FixedPointMathLib} from "solady/utils/FixedPointMathLib.sol"; | ||
|
||
contract ExponentialPremiumFuzzTest is LaunchAuctionPriceOracleBase { | ||
function test_decayedPremium_decreasingPrices(uint256 elapsed) public view { | ||
elapsed = bound(elapsed, 0, totalDays * 1 days); | ||
uint256 actualPremium = oracle.decayedPremium(elapsed); | ||
assert(actualPremium <= startPremium); | ||
} | ||
|
||
function test_decayedPremium_alwaysDecreasing(uint256 elapsed1, uint256 elapsed2) public view { | ||
vm.assume(elapsed1 < elapsed2 && (elapsed1 < totalDays * 1 days)); | ||
elapsed1 = bound(elapsed1, 0, elapsed2); | ||
elapsed2 = bound(elapsed2, elapsed1, totalDays * 1 days); | ||
|
||
uint256 premium1 = oracle.decayedPremium(elapsed1); | ||
uint256 premium2 = oracle.decayedPremium(elapsed2); | ||
|
||
assert(premium1 >= premium2); | ||
} | ||
} |
53 changes: 53 additions & 0 deletions
53
test/LaunchAuctionPriceOracle/LaunchAuctionPriceOracleBase.t.sol
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
//SPDX-License-Identifier: MIT | ||
pragma solidity ^0.8.17; | ||
|
||
import {Test} from "forge-std/Test.sol"; | ||
import {StablePriceOracle} from "src/L2/StablePriceOracle.sol"; | ||
import {LaunchAuctionPriceOracle} from "src/L2/LaunchAuctionPriceOracle.sol"; | ||
|
||
contract LaunchAuctionPriceOracleBase is Test { | ||
LaunchAuctionPriceOracle oracle; | ||
|
||
uint256 rent1; | ||
uint256 rent2; | ||
uint256 rent3; | ||
uint256 rent4; | ||
uint256 rent5; | ||
uint256 rent10; | ||
|
||
uint256 startPremium = 100 ether; | ||
uint256 totalDays = 1; | ||
|
||
uint256 hoursPerDay = 24; | ||
|
||
function setUp() public { | ||
uint256[] memory rentPrices = new uint256[](6); | ||
|
||
rent1 = 316_808_781_402; | ||
rent2 = 31_680_878_140; | ||
rent3 = 3_168_087_814; | ||
rent4 = 316_808_781; | ||
rent5 = 31_680_878; | ||
rent10 = 3_168_087; // 3,168,808.781402895 = 1e14 / (365.25 * 24 * 3600) | ||
|
||
rentPrices[0] = rent1; | ||
rentPrices[1] = rent2; | ||
rentPrices[2] = rent3; | ||
rentPrices[3] = rent4; | ||
rentPrices[4] = rent5; | ||
rentPrices[5] = rent10; | ||
|
||
oracle = new LaunchAuctionPriceOracle(rentPrices, startPremium, totalDays); | ||
} | ||
|
||
function test_constructor() public view { | ||
assertEq(oracle.startPremium(), startPremium); | ||
assertEq(oracle.endValue(), startPremium >> (totalDays * hoursPerDay)); | ||
assertEq(oracle.price1Letter(), rent1); | ||
assertEq(oracle.price2Letter(), rent2); | ||
assertEq(oracle.price3Letter(), rent3); | ||
assertEq(oracle.price4Letter(), rent4); | ||
assertEq(oracle.price5Letter(), rent5); | ||
assertEq(oracle.price10Letter(), rent10); | ||
} | ||
} |